2017-03-24 20:19:04 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2017-03-25 00:47:01 +01:00
|
|
|
import com.massivecraft.factions.Rel;
|
|
|
|
import com.massivecraft.factions.TerritoryAccess;
|
|
|
|
import com.massivecraft.factions.entity.Board;
|
2017-03-24 20:19:04 +01:00
|
|
|
import com.massivecraft.factions.entity.BoardColl;
|
2017-03-25 00:47:01 +01:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
|
|
|
import com.massivecraft.factions.entity.FactionColl;
|
2017-04-20 11:05:56 +02:00
|
|
|
import com.massivecraft.factions.entity.Invitation;
|
2019-04-14 23:18:10 +02:00
|
|
|
import com.massivecraft.factions.entity.MPerm;
|
2017-03-25 00:47:01 +01:00
|
|
|
import com.massivecraft.factions.entity.MPlayer;
|
2017-03-24 20:19:04 +01:00
|
|
|
import com.massivecraft.factions.entity.MPlayerColl;
|
|
|
|
import com.massivecraft.massivecore.MassiveException;
|
2017-05-28 17:56:37 +02:00
|
|
|
import com.massivecraft.massivecore.collections.MassiveSet;
|
2017-03-25 00:47:01 +01:00
|
|
|
import com.massivecraft.massivecore.ps.PS;
|
2017-04-20 11:05:56 +02:00
|
|
|
import com.massivecraft.massivecore.store.EntityInternalMap;
|
2017-03-24 20:19:04 +01:00
|
|
|
import com.massivecraft.massivecore.util.Txt;
|
|
|
|
|
2017-03-25 00:47:01 +01:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map.Entry;
|
2017-05-28 17:56:37 +02:00
|
|
|
import java.util.Set;
|
2017-03-25 00:47:01 +01:00
|
|
|
|
2017-03-24 20:19:04 +01:00
|
|
|
public class CmdFactionsClean extends FactionsCommand
|
|
|
|
{
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() throws MassiveException
|
|
|
|
{
|
|
|
|
Object message;
|
2017-03-25 00:47:01 +01:00
|
|
|
int count;
|
2017-03-24 20:19:04 +01:00
|
|
|
|
|
|
|
// Title
|
|
|
|
message = Txt.titleize("Factions Cleaner Results");
|
|
|
|
message(message);
|
|
|
|
|
2017-03-25 00:47:01 +01:00
|
|
|
// Yada
|
|
|
|
cleanMessage(this.cleanPlayer(), "player");
|
|
|
|
cleanMessage(this.cleanFactionInvites(), "faction invites");
|
|
|
|
cleanMessage(this.cleanFactionRelationWhishes(), "faction relation whishes");
|
|
|
|
cleanMessage(this.cleanBoardHost(), "chunk whole");
|
|
|
|
cleanMessage(this.cleanBoardGrant(), "chunk access");
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// CLEAN
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
private void cleanMessage(int count, String name)
|
|
|
|
{
|
|
|
|
msg("<v>%d<k> %s", count, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int cleanPlayer()
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2017-03-24 20:19:04 +01:00
|
|
|
|
2017-03-25 00:47:01 +01:00
|
|
|
for (MPlayer mplayer : MPlayerColl.get().getAll())
|
|
|
|
{
|
|
|
|
if (!mplayer.isFactionOrphan()) continue;
|
|
|
|
|
|
|
|
mplayer.resetFactionData();
|
|
|
|
ret += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int cleanFactionInvites()
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
for (Faction faction : FactionColl.get().getAll())
|
|
|
|
{
|
2017-04-20 11:05:56 +02:00
|
|
|
EntityInternalMap<Invitation> invitations = faction.getInvitations();
|
|
|
|
if (invitations.isEmpty()) continue;
|
2017-03-25 00:47:01 +01:00
|
|
|
|
2017-04-20 11:05:56 +02:00
|
|
|
ret += invitations.size();
|
2017-05-28 17:56:37 +02:00
|
|
|
Set<String> invitationIds = new MassiveSet<>(invitations.keySet());
|
|
|
|
for (String inviteId : invitationIds)
|
|
|
|
{
|
|
|
|
invitations.detachIdFixed(inviteId);
|
|
|
|
}
|
|
|
|
|
2017-03-25 00:47:01 +01:00
|
|
|
faction.changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int cleanFactionRelationWhishes()
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
for (Faction faction : FactionColl.get().getAll())
|
|
|
|
{
|
|
|
|
for (Iterator<Entry<String, Rel>> iterator = faction.getRelationWishes().entrySet().iterator(); iterator.hasNext();)
|
|
|
|
{
|
|
|
|
Entry<String, Rel> entry = iterator.next();
|
|
|
|
String factionId = entry.getKey();
|
|
|
|
if (FactionColl.get().containsId(factionId)) continue;
|
|
|
|
|
|
|
|
iterator.remove();
|
|
|
|
ret += 1;
|
|
|
|
faction.changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int cleanBoardHost()
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
for (Board board : BoardColl.get().getAll())
|
|
|
|
{
|
|
|
|
for (Entry<PS, TerritoryAccess> entry : board.getMap().entrySet())
|
|
|
|
{
|
|
|
|
PS ps = entry.getKey();
|
|
|
|
TerritoryAccess territoryAccess = entry.getValue();
|
|
|
|
String factionId = territoryAccess.getHostFactionId();
|
|
|
|
|
|
|
|
if (FactionColl.get().containsId(factionId)) continue;
|
|
|
|
|
|
|
|
board.removeAt(ps);
|
|
|
|
ret += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int cleanBoardGrant()
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
for (Board board : BoardColl.get().getAll())
|
|
|
|
{
|
|
|
|
for (Entry<PS, TerritoryAccess> entry : board.getMap().entrySet())
|
|
|
|
{
|
|
|
|
PS ps = entry.getKey();
|
|
|
|
TerritoryAccess territoryAccess = entry.getValue();
|
|
|
|
boolean changed = false;
|
|
|
|
|
2019-04-14 23:18:10 +02:00
|
|
|
for (String grantedIds : territoryAccess.getGrantedIds())
|
2017-03-25 00:47:01 +01:00
|
|
|
{
|
2019-04-14 23:18:10 +02:00
|
|
|
if (MPerm.idToMPermableOptional(grantedIds).isPresent()) continue;
|
2017-03-25 00:47:01 +01:00
|
|
|
|
2019-04-14 23:18:10 +02:00
|
|
|
territoryAccess = territoryAccess.withGrantedId(grantedIds, false);
|
2017-03-25 00:47:01 +01:00
|
|
|
ret += 1;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
board.setTerritoryAccessAt(ps, territoryAccess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2017-03-24 20:19:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|