Add clean command
This commit is contained in:
		@@ -89,6 +89,7 @@ public enum Perm implements Identified
 | 
			
		||||
	UNSETHOME,
 | 
			
		||||
	UNSTUCK,
 | 
			
		||||
	CONFIG,
 | 
			
		||||
	CLEAN,
 | 
			
		||||
	VERSION,
 | 
			
		||||
	
 | 
			
		||||
	// END OF LIST
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsClean.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsClean.java
									
									
									
									
									
										Normal 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);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user