Add clean command

This commit is contained in:
Olof Larsson 2017-03-24 20:19:04 +01:00
parent 42fe618b6b
commit 59112577b8
8 changed files with 66 additions and 5 deletions

View File

@ -89,6 +89,7 @@ permissions:
factions.unsethome: {description: unset faction home, default: false}
factions.unstuck: {description: teleport to nearest wilderness, default: false}
factions.config: {description: edit the factions config, default: false}
factions.clean: {description: clean the factions database, default: false}
factions.version: {description: see plugin version, default: false}
# -------------------------------------------- #
# STAR NOTATION
@ -177,6 +178,7 @@ permissions:
factions.unsethome: true
factions.unstuck: true
factions.config: true
factions.clean: true
factions.version: true
# -------------------------------------------- #
# KITS
@ -190,6 +192,7 @@ permissions:
children:
factions.kit.rank2: true
factions.config: true
factions.clean: true
factions.kit.rank2:
default: false
children:

View File

@ -89,6 +89,7 @@ public enum Perm implements Identified
UNSETHOME,
UNSTUCK,
CONFIG,
CLEAN,
VERSION,
// END OF LIST

View File

@ -69,6 +69,7 @@ public class CmdFactions extends FactionsCommand
public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost();
public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower();
public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig();
public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean();
public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()).setAliases("v", "version").addRequirements(RequirementHasPerm.get(Perm.VERSION));
// -------------------------------------------- //
@ -125,6 +126,7 @@ public class CmdFactions extends FactionsCommand
this.addChild(this.cmdFactionsPowerBoost);
this.addChild(this.cmdFactionsSetpower);
this.addChild(this.cmdFactionsConfig);
this.addChild(this.cmdFactionsClean);
this.addChild(this.cmdFactionsVersion);
// Deprecated Commands

View File

@ -0,0 +1,36 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.MPlayerColl;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsClean extends FactionsCommand
{
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
Object message;
// Apply
int chunks = BoardColl.get().clean();
int players = MPlayerColl.get().clean();
// Title
message = Txt.titleize("Factions Cleaner Results");
message(message);
// Chunks
message = Txt.parse("<h>%d<i> chunks were cleaned.", chunks);
message(message);
// Players
message = Txt.parse("<h>%d<i> players were cleaned.", players);
message(message);
}
}

View File

@ -159,8 +159,12 @@ public class Board extends Entity<Board> implements BoardInterface
// Removes orphaned foreign keys
@Override
public void clean()
public int clean()
{
int ret = 0;
if (!FactionColl.get().isActive()) return ret;
for (Entry<PS, TerritoryAccess> entry : this.map.entrySet())
{
TerritoryAccess territoryAccess = entry.getValue();
@ -171,8 +175,12 @@ public class Board extends Entity<Board> implements BoardInterface
PS ps = entry.getKey();
this.removeAt(ps);
ret += 0;
Factions.get().log("Board cleaner removed "+factionId+" from "+ps);
}
return ret;
}
// CHUNKS

View File

@ -118,12 +118,16 @@ public class BoardColl extends Coll<Board> implements BoardInterface
}
@Override
public void clean()
public int clean()
{
int ret = 0;
for (Board board : this.getAll())
{
board.clean();
ret += board.clean();
}
return ret;
}
// CHUNKS

View File

@ -21,7 +21,7 @@ public interface BoardInterface
// REMOVE
void removeAt(PS ps);
void removeAll(Faction faction);
void clean();
int clean();
// CHUNKS
Set<PS> getChunks(Faction faction);

View File

@ -82,8 +82,12 @@ public class MPlayerColl extends SenderColl<MPlayer>
// EXTRAS
// -------------------------------------------- //
public void clean()
public int clean()
{
int ret = 0;
if (!FactionColl.get().isActive()) return ret;
// For each player ...
for (MPlayer mplayer : this.getAll())
{
@ -93,11 +97,14 @@ public class MPlayerColl extends SenderColl<MPlayer>
// ... reset their faction data ...
mplayer.resetFactionData();
ret += 1;
// ... and log.
String message = Txt.parse("<i>Reset data for <h>%s <i>. Unknown factionId <h>%s", mplayer.getDisplayName(IdUtil.getConsole()), factionId);
Factions.get().log(message);
}
return ret;
}
public void considerRemovePlayerMillis()