Fewer and fewer errors...
This commit is contained in:
		@@ -55,7 +55,7 @@ public class Board {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public static void setFactionAt(Faction faction, FLocation flocation) {
 | 
						public static void setFactionAt(Faction faction, FLocation flocation) {
 | 
				
			||||||
		setIdAt(faction.id, flocation);
 | 
							setIdAt(faction.getId(), flocation);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public static void removeAt(FLocation flocation) {
 | 
						public static void removeAt(FLocation flocation) {
 | 
				
			||||||
@@ -112,7 +112,7 @@ public class Board {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public static int getFactionCoordCount(Faction faction) {
 | 
						public static int getFactionCoordCount(Faction faction) {
 | 
				
			||||||
		return getFactionCoordCount(faction.id);
 | 
							return getFactionCoordCount(faction.getId());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	//----------------------------------------------//
 | 
						//----------------------------------------------//
 | 
				
			||||||
@@ -144,7 +144,7 @@ public class Board {
 | 
				
			|||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					FLocation flocationHere = topLeft.getRelative(dx, dz);
 | 
										FLocation flocationHere = topLeft.getRelative(dx, dz);
 | 
				
			||||||
					Faction factionHere = getFactionAt(flocationHere);
 | 
										Faction factionHere = getFactionAt(flocationHere);
 | 
				
			||||||
					if (factionHere.id == 0) {
 | 
										if (factionHere.getId() == 0) {
 | 
				
			||||||
						row += ChatColor.GRAY+"-";
 | 
											row += ChatColor.GRAY+"-";
 | 
				
			||||||
					} else {
 | 
										} else {
 | 
				
			||||||
						row += factionHere.getRelation(faction).getColor()+"+";
 | 
											row += factionHere.getRelation(faction).getColor()+"+";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,8 @@ import org.bukkit.entity.Player;
 | 
				
			|||||||
public class FLocation {
 | 
					public class FLocation {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private String worldName = "world";
 | 
						private String worldName = "world";
 | 
				
			||||||
	private long x = 0;
 | 
						private int x = 0;
 | 
				
			||||||
	private long z = 0;
 | 
						private int z = 0;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private final static transient double cellSize = 16;
 | 
						private final static transient double cellSize = 16;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@@ -20,14 +20,14 @@ public class FLocation {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public FLocation(String worldName, long x, long z) {
 | 
						public FLocation(String worldName, int x, int z) {
 | 
				
			||||||
		this.worldName = worldName;
 | 
							this.worldName = worldName;
 | 
				
			||||||
		this.x = x;
 | 
							this.x = x;
 | 
				
			||||||
		this.z = z;
 | 
							this.z = z;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public FLocation(Location location) {
 | 
						public FLocation(Location location) {
 | 
				
			||||||
		this(location.getWorld().getName(), (long) Math.floor(location.getX() / cellSize) , (long) Math.floor(location.getZ() / cellSize));
 | 
							this(location.getWorld().getName(), (int) Math.floor(location.getX() / cellSize) , (int) Math.floor(location.getZ() / cellSize));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public FLocation(Player player) {
 | 
						public FLocation(Player player) {
 | 
				
			||||||
@@ -58,7 +58,7 @@ public class FLocation {
 | 
				
			|||||||
		return x;
 | 
							return x;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public void setX(long x) {
 | 
						public void setX(int x) {
 | 
				
			||||||
		this.x = x;
 | 
							this.x = x;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -66,7 +66,7 @@ public class FLocation {
 | 
				
			|||||||
		return z;
 | 
							return z;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public void setZ(long z) {
 | 
						public void setZ(int z) {
 | 
				
			||||||
		this.z = z;
 | 
							this.z = z;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@@ -86,8 +86,6 @@ public class FLocation {
 | 
				
			|||||||
	// Comparison
 | 
						// Comparison
 | 
				
			||||||
	//----------------------------------------------//
 | 
						//----------------------------------------------//
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// TODO hash code
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public boolean equals(Object obj) {
 | 
						public boolean equals(Object obj) {
 | 
				
			||||||
		if (obj == this)
 | 
							if (obj == this)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,20 +27,29 @@ import com.bukkit.mcteam.util.DiscUtil;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class FPlayer {
 | 
					public class FPlayer {
 | 
				
			||||||
	public static transient Map<String, FPlayer> instances = new HashMap<String, FPlayer>();
 | 
					 | 
				
			||||||
	public static transient File file = new File(Factions.instance.getDataFolder(), "players.json");
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public transient String playerName;
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	public transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked?
 | 
						// Fields
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public int factionId;
 | 
						private static transient Map<String, FPlayer> instances = new HashMap<String, FPlayer>();
 | 
				
			||||||
	public Role role;
 | 
						private static transient File file = new File(Factions.instance.getDataFolder(), "players.json");
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private transient String playerName;
 | 
				
			||||||
 | 
						private transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked?
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private int factionId;
 | 
				
			||||||
 | 
						private Role role;
 | 
				
			||||||
	private String title;
 | 
						private String title;
 | 
				
			||||||
	private double power;
 | 
						private double power;
 | 
				
			||||||
	private long lastPowerUpdateTime;
 | 
						private long lastPowerUpdateTime;
 | 
				
			||||||
	private transient boolean mapAutoUpdating;
 | 
						private transient boolean mapAutoUpdating;
 | 
				
			||||||
	private boolean factionChatting; 
 | 
						private boolean factionChatting; 
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// Construct
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	public FPlayer(Player player) {
 | 
						public FPlayer(Player player) {
 | 
				
			||||||
		this.playerName = player.getName().toLowerCase();
 | 
							this.playerName = player.getName().toLowerCase();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -64,18 +73,20 @@ public class FPlayer {
 | 
				
			|||||||
		this.title = "";
 | 
							this.title = "";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// Minecraft Player
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	public Player getPlayer() {
 | 
						public Player getPlayer() {
 | 
				
			||||||
		return Factions.instance.getServer().getPlayer(playerName);
 | 
							return Factions.instance.getServer().getPlayer(playerName);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// TODO lowercase vs mixedcase for logged in chars...
 | 
				
			||||||
	public String getPlayerName() {
 | 
						public String getPlayerName() {
 | 
				
			||||||
		return this.playerName;
 | 
							return this.playerName;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// -------------------------------------------- //
 | 
					 | 
				
			||||||
	// Online / Offline State Checking
 | 
					 | 
				
			||||||
	// -------------------------------------------- //
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public boolean isOnline() {
 | 
						public boolean isOnline() {
 | 
				
			||||||
		return Factions.instance.getServer().getPlayer(playerName) != null;
 | 
							return Factions.instance.getServer().getPlayer(playerName) != null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -84,6 +95,30 @@ public class FPlayer {
 | 
				
			|||||||
		return ! isOnline();
 | 
							return ! isOnline();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// Getters And Setters
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public Faction getFaction() {
 | 
				
			||||||
 | 
							return Faction.get(factionId);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public void setFaction(Faction faction) {
 | 
				
			||||||
 | 
							this.factionId = faction.getId();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public boolean hasFaction() {
 | 
				
			||||||
 | 
							return factionId != 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public Role getRole() {
 | 
				
			||||||
 | 
							return this.role;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public void setRole(Role role) {
 | 
				
			||||||
 | 
							this.role = role;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	public boolean isFactionChatting() {
 | 
						public boolean isFactionChatting() {
 | 
				
			||||||
		if (this.factionId == 0) {
 | 
							if (this.factionId == 0) {
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
@@ -95,8 +130,6 @@ public class FPlayer {
 | 
				
			|||||||
		this.factionChatting = factionChatting;
 | 
							this.factionChatting = factionChatting;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public boolean isMapAutoUpdating() {
 | 
						public boolean isMapAutoUpdating() {
 | 
				
			||||||
		return mapAutoUpdating;
 | 
							return mapAutoUpdating;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -105,6 +138,14 @@ public class FPlayer {
 | 
				
			|||||||
		this.mapAutoUpdating = mapAutoUpdating;
 | 
							this.mapAutoUpdating = mapAutoUpdating;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						public FLocation getLastStoodAt() {
 | 
				
			||||||
 | 
							return this.lastStoodAt;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public void setLastStoodAt(FLocation flocation) {
 | 
				
			||||||
 | 
							this.lastStoodAt = flocation;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	//----------------------------------------------//
 | 
						//----------------------------------------------//
 | 
				
			||||||
	// Title, Name, Faction Tag and Chat
 | 
						// Title, Name, Faction Tag and Chat
 | 
				
			||||||
	//----------------------------------------------//
 | 
						//----------------------------------------------//
 | 
				
			||||||
@@ -300,7 +341,7 @@ public class FPlayer {
 | 
				
			|||||||
	// Territory
 | 
						// Territory
 | 
				
			||||||
	//----------------------------------------------//
 | 
						//----------------------------------------------//
 | 
				
			||||||
	public boolean isInOwnTerritory() {
 | 
						public boolean isInOwnTerritory() {
 | 
				
			||||||
		return Board.getIdAt(new FLocation(this)) == this.factionId;
 | 
							return Board.getFactionAt(new FLocation(this)) == this.getFaction();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public boolean isInOthersTerritory() {
 | 
						public boolean isInOthersTerritory() {
 | 
				
			||||||
@@ -311,21 +352,23 @@ public class FPlayer {
 | 
				
			|||||||
	public void sendFactionHereMessage() {
 | 
						public void sendFactionHereMessage() {
 | 
				
			||||||
		Faction factionHere = Board.getFactionAt(new FLocation(this));
 | 
							Faction factionHere = Board.getFactionAt(new FLocation(this));
 | 
				
			||||||
		String msg = Conf.colorSystem+" ~ "+factionHere.getTag(this);
 | 
							String msg = Conf.colorSystem+" ~ "+factionHere.getTag(this);
 | 
				
			||||||
		if (factionHere.id != 0) {
 | 
							if (factionHere.getId() != 0) {
 | 
				
			||||||
			msg += " - "+factionHere.getDescription();
 | 
								msg += " - "+factionHere.getDescription();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		this.sendMessage(msg);
 | 
							this.sendMessage(msg);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	//----------------------------------------------//
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// Faction management
 | 
						// Messages
 | 
				
			||||||
	//----------------------------------------------//
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	public Faction getFaction() {
 | 
						public void sendMessage(String message) {
 | 
				
			||||||
		return Faction.get(factionId);
 | 
							this.getPlayer().sendMessage(Conf.colorSystem + message);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public boolean hasFaction() {
 | 
						public void sendMessage(List<String> messages) {
 | 
				
			||||||
		return factionId != 0;
 | 
							for(String message : messages) {
 | 
				
			||||||
 | 
								this.sendMessage(message);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
@@ -368,19 +411,6 @@ public class FPlayer {
 | 
				
			|||||||
		return null;
 | 
							return null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// -------------------------------------------- //
 | 
					 | 
				
			||||||
	// Messages
 | 
					 | 
				
			||||||
	// -------------------------------------------- //
 | 
					 | 
				
			||||||
	public void sendMessage(String message) {
 | 
					 | 
				
			||||||
		this.getPlayer().sendMessage(Conf.colorSystem + message);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public void sendMessage(List<String> messages) {
 | 
					 | 
				
			||||||
		for(String message : messages) {
 | 
					 | 
				
			||||||
			this.sendMessage(message);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// Persistance
 | 
						// Persistance
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,6 @@ import java.util.logging.Level;
 | 
				
			|||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.bukkit.mcteam.factions.entities.EM;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.struct.Relation;
 | 
					import com.bukkit.mcteam.factions.struct.Relation;
 | 
				
			||||||
import com.bukkit.mcteam.factions.struct.Role;
 | 
					import com.bukkit.mcteam.factions.struct.Role;
 | 
				
			||||||
import com.bukkit.mcteam.factions.util.*;
 | 
					import com.bukkit.mcteam.factions.util.*;
 | 
				
			||||||
@@ -18,16 +17,25 @@ import com.bukkit.mcteam.gson.reflect.TypeToken;
 | 
				
			|||||||
import com.bukkit.mcteam.util.DiscUtil;
 | 
					import com.bukkit.mcteam.util.DiscUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Faction {
 | 
					public class Faction {
 | 
				
			||||||
	public static transient Map<Integer, Faction> instances = new HashMap<Integer, Faction>();
 | 
					 | 
				
			||||||
	public static transient File file = new File(Factions.instance.getDataFolder(), "factions.json");
 | 
					 | 
				
			||||||
	public static transient int nextId;
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public transient int id;
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	protected Map<Integer, Relation> relationWish;
 | 
						// Fields
 | 
				
			||||||
	public Set<String> invites; // Where string is a follower id (lower case name)
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	protected boolean open;
 | 
						
 | 
				
			||||||
	protected String tag;
 | 
						private static transient Map<Integer, Faction> instances = new HashMap<Integer, Faction>();
 | 
				
			||||||
	protected String description;
 | 
						private static transient File file = new File(Factions.instance.getDataFolder(), "factions.json");
 | 
				
			||||||
 | 
						private static transient int nextId;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private transient int id;
 | 
				
			||||||
 | 
						private Map<Integer, Relation> relationWish;
 | 
				
			||||||
 | 
						private Set<String> invites; // Where string is a follower id (lower case name)
 | 
				
			||||||
 | 
						private boolean open;
 | 
				
			||||||
 | 
						private String tag;
 | 
				
			||||||
 | 
						private String description;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// Construct
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public Faction() {
 | 
						public Faction() {
 | 
				
			||||||
		this.relationWish = new HashMap<Integer, Relation>();
 | 
							this.relationWish = new HashMap<Integer, Relation>();
 | 
				
			||||||
@@ -37,6 +45,69 @@ public class Faction {
 | 
				
			|||||||
		this.description = "Default faction description :(";
 | 
							this.description = "Default faction description :(";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// Getters And Setters
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public int getId() {
 | 
				
			||||||
 | 
							return this.id;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------
 | 
				
			||||||
 | 
						// Invites
 | 
				
			||||||
 | 
						// -------------------------------
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public void invite(FPlayer fplayer) {
 | 
				
			||||||
 | 
							this.invites.add(fplayer.getName()); //TODO Lowercase paradigm shit....
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public void deinvite(FPlayer fplayer) {
 | 
				
			||||||
 | 
							this.invites.remove(fplayer.getName()); //TODO Lowercase paradigm shit....
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public boolean isInvited(FPlayer fplayer) {
 | 
				
			||||||
 | 
							return this.invites.contains(fplayer.getName()); //TODO Lowercase paradigm shit....
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------
 | 
				
			||||||
 | 
						// Relation and relation colors TODO
 | 
				
			||||||
 | 
						// -------------------------------
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public Relation getRelationWish(Faction otherFaction) {
 | 
				
			||||||
 | 
							if (this.relationWish.containsKey(otherFaction.getId())){
 | 
				
			||||||
 | 
								return this.relationWish.get(otherFaction.getId());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return Relation.NEUTRAL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public void setRelationWish(Faction otherFaction, Relation relation) {
 | 
				
			||||||
 | 
							if (this.relationWish.containsKey(otherFaction.getId()) && relation.equals(Relation.NEUTRAL)){
 | 
				
			||||||
 | 
								this.relationWish.remove(otherFaction.getId());
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								this.relationWish.put(otherFaction.getId(), relation);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							Faction.save();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public Relation getRelation(Faction otherFaction) {
 | 
				
			||||||
 | 
							if (otherFaction.getId() == 0 || this.getId() == 0) {
 | 
				
			||||||
 | 
								return Relation.NEUTRAL;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (otherFaction.equals(this)) {
 | 
				
			||||||
 | 
								return Relation.MEMBER;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if(this.getRelationWish(otherFaction).value >= otherFaction.getRelationWish(this).value) {
 | 
				
			||||||
 | 
								return otherFaction.getRelationWish(this);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return this.getRelationWish(otherFaction);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public Relation getRelation(FPlayer follower) {
 | 
				
			||||||
 | 
							return getRelation(follower.getFaction());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	// -------------------------------
 | 
						// -------------------------------
 | 
				
			||||||
	// Information
 | 
						// Information
 | 
				
			||||||
	// -------------------------------
 | 
						// -------------------------------
 | 
				
			||||||
@@ -106,62 +177,13 @@ public class Faction {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public int getLandRounded() {
 | 
						public int getLandRounded() {
 | 
				
			||||||
		return Board.getFactionCoordCountAllBoards(this);
 | 
							return Board.getFactionCoordCount(this);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public boolean hasLandInflation() {
 | 
						public boolean hasLandInflation() {
 | 
				
			||||||
		return this.getLandRounded() > this.getPowerRounded();
 | 
							return this.getLandRounded() > this.getPowerRounded();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// -------------------------------
 | 
					 | 
				
			||||||
	// Membership management
 | 
					 | 
				
			||||||
	// -------------------------------
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	/*public ArrayList<String> invite(FPlayer follower) { // TODO Move out
 | 
					 | 
				
			||||||
		ArrayList<String> errors = new ArrayList<String>();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (follower.getFaction().equals(this)) { // error här?
 | 
					 | 
				
			||||||
			errors.add(Conf.colorSystem+follower.getName()+" is already a member of "+this.getTag());
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if(errors.size() > 0) {
 | 
					 | 
				
			||||||
			return errors;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		this.invites.add(follower.id);
 | 
					 | 
				
			||||||
		this.save();
 | 
					 | 
				
			||||||
		return errors;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public ArrayList<String> deinvite(FPlayer follower) { // TODO move out!
 | 
					 | 
				
			||||||
		ArrayList<String> errors = new ArrayList<String>();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (follower.getFaction() == this) {
 | 
					 | 
				
			||||||
			errors.add(Conf.colorSystem+follower.getName()+" is already a member of "+this.getTag());
 | 
					 | 
				
			||||||
			errors.add(Conf.colorSystem+"You might want to "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasKick.get(0)+Conf.colorParameter+" "+follower.getName());
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if(errors.size() > 0) {
 | 
					 | 
				
			||||||
			return errors;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		this.invites.remove(follower.id);
 | 
					 | 
				
			||||||
		this.save();
 | 
					 | 
				
			||||||
		return errors;
 | 
					 | 
				
			||||||
	}*/
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public ArrayList<String> kick(FPlayer follower) {
 | 
					 | 
				
			||||||
		ArrayList<String> errors = new ArrayList<String>();
 | 
					 | 
				
			||||||
		removeFollower(follower);
 | 
					 | 
				
			||||||
		return errors;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public boolean isInvited(FPlayer follower) {
 | 
					 | 
				
			||||||
		return invites.contains(follower.id);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// -------------------------------
 | 
						// -------------------------------
 | 
				
			||||||
	// Followers
 | 
						// Followers
 | 
				
			||||||
	// -------------------------------
 | 
						// -------------------------------
 | 
				
			||||||
@@ -169,7 +191,7 @@ public class Faction {
 | 
				
			|||||||
	public ArrayList<FPlayer> getFPlayers() {
 | 
						public ArrayList<FPlayer> getFPlayers() {
 | 
				
			||||||
		ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
 | 
							ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
 | 
				
			||||||
		for (FPlayer follower : FPlayer.getAll()) {
 | 
							for (FPlayer follower : FPlayer.getAll()) {
 | 
				
			||||||
			if (follower.factionId == this.id) {
 | 
								if (follower.getFaction() == this) {
 | 
				
			||||||
				ret.add(follower);
 | 
									ret.add(follower);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -178,9 +200,9 @@ public class Faction {
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	public ArrayList<FPlayer> getFPlayersWhereOnline(boolean online) {
 | 
						public ArrayList<FPlayer> getFPlayersWhereOnline(boolean online) {
 | 
				
			||||||
		ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
 | 
							ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
 | 
				
			||||||
		for (FPlayer follower : FPlayer.getAll()) {
 | 
							for (FPlayer fplayer : FPlayer.getAll()) {
 | 
				
			||||||
			if (follower.factionId == this.id && follower.isOnline() == online) {
 | 
								if (fplayer.getFaction() == this && fplayer.isOnline() == online) {
 | 
				
			||||||
				ret.add(follower);
 | 
									ret.add(fplayer);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return ret;
 | 
							return ret;
 | 
				
			||||||
@@ -189,9 +211,9 @@ public class Faction {
 | 
				
			|||||||
	public ArrayList<FPlayer> getFPlayersWhereRole(Role role) {
 | 
						public ArrayList<FPlayer> getFPlayersWhereRole(Role role) {
 | 
				
			||||||
		ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
 | 
							ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		for (FPlayer follower : FPlayer.getAll()) {
 | 
							for (FPlayer fplayer : FPlayer.getAll()) {
 | 
				
			||||||
			if (follower.factionId == this.id && follower.role.equals(role)) {
 | 
								if (fplayer.getFaction() == this && fplayer.getRole() == role) {
 | 
				
			||||||
				ret.add(follower);
 | 
									ret.add(fplayer);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@@ -214,7 +236,7 @@ public class Faction {
 | 
				
			|||||||
		ArrayList<Player> ret = new ArrayList<Player>();
 | 
							ArrayList<Player> ret = new ArrayList<Player>();
 | 
				
			||||||
		for (Player player: Factions.instance.getServer().getOnlinePlayers()) {
 | 
							for (Player player: Factions.instance.getServer().getOnlinePlayers()) {
 | 
				
			||||||
			FPlayer follower = FPlayer.get(player);
 | 
								FPlayer follower = FPlayer.get(player);
 | 
				
			||||||
			if (follower.factionId == this.id) {
 | 
								if (follower.getFaction() == this) {
 | 
				
			||||||
				ret.add(player);
 | 
									ret.add(player);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -264,57 +286,23 @@ public class Faction {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	//----------------------------------------------//
 | 
						//----------------------------------------------//
 | 
				
			||||||
	// Messages - Directly connected to ChatFixUtil
 | 
						// Messages
 | 
				
			||||||
	//----------------------------------------------//
 | 
						//----------------------------------------------//
 | 
				
			||||||
	public void sendMessage(String message, boolean fix) {
 | 
					 | 
				
			||||||
		ChatFixUtil.sendMessage(this.getOnlinePlayers(), message, fix);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	public void sendMessage(List<String> messages, boolean fix) {
 | 
					 | 
				
			||||||
		ChatFixUtil.sendMessage(this.getOnlinePlayers(), messages, fix);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	public void sendMessage(String message) {
 | 
						public void sendMessage(String message) {
 | 
				
			||||||
		ChatFixUtil.sendMessage(this.getOnlinePlayers(), message, true);
 | 
							for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) {
 | 
				
			||||||
 | 
								fplayer.sendMessage(message);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	public void sendMessage(List<String> messages) {
 | 
						public void sendMessage(List<String> messages) {
 | 
				
			||||||
		ChatFixUtil.sendMessage(this.getOnlinePlayers(), messages, true);
 | 
							for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) {
 | 
				
			||||||
 | 
								fplayer.sendMessage(messages);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// -------------------------------
 | 
						//----------------------------------------------//
 | 
				
			||||||
	// Relation and relation colors
 | 
						// Mudd TODO
 | 
				
			||||||
	// -------------------------------
 | 
						//----------------------------------------------//
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public Relation getRelationWish(Faction otherFaction) {
 | 
					 | 
				
			||||||
		if (this.relationWish.containsKey(otherFaction.id)){
 | 
					 | 
				
			||||||
			return this.relationWish.get(otherFaction.id);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return Relation.NEUTRAL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public void setRelationWish(Faction otherFaction, Relation relation) {
 | 
					 | 
				
			||||||
		if (this.relationWish.containsKey(otherFaction.id) && relation.equals(Relation.NEUTRAL)){
 | 
					 | 
				
			||||||
			this.relationWish.remove(otherFaction.id);
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			this.relationWish.put(otherFaction.id, relation);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		this.save();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public Relation getRelation(Faction otherFaction) {
 | 
					 | 
				
			||||||
		if (otherFaction.id == 0 || this.id == 0) {
 | 
					 | 
				
			||||||
			return Relation.NEUTRAL;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (otherFaction.equals(this)) {
 | 
					 | 
				
			||||||
			return Relation.MEMBER;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if(this.getRelationWish(otherFaction).value >= otherFaction.getRelationWish(this).value) {
 | 
					 | 
				
			||||||
			return otherFaction.getRelationWish(this);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return this.getRelationWish(otherFaction);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public Relation getRelation(FPlayer follower) {
 | 
					 | 
				
			||||||
		return getRelation(follower.getFaction());
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public ChatColor getRelationColor(Faction otherFaction) {
 | 
						public ChatColor getRelationColor(Faction otherFaction) {
 | 
				
			||||||
		return this.getRelation(otherFaction).getColor();
 | 
							return this.getRelation(otherFaction).getColor();
 | 
				
			||||||
@@ -324,6 +312,8 @@ public class Faction {
 | 
				
			|||||||
		return this.getRelation(follower).getColor();
 | 
							return this.getRelation(follower).getColor();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	//----------------------------------------------//
 | 
						//----------------------------------------------//
 | 
				
			||||||
	// Persistance and entity management
 | 
						// Persistance and entity management
 | 
				
			||||||
	//----------------------------------------------//
 | 
						//----------------------------------------------//
 | 
				
			||||||
@@ -385,7 +375,7 @@ public class Faction {
 | 
				
			|||||||
	public static Faction get(Integer factionId) {
 | 
						public static Faction get(Integer factionId) {
 | 
				
			||||||
		if ( ! instances.containsKey(factionId)) {
 | 
							if ( ! instances.containsKey(factionId)) {
 | 
				
			||||||
			Factions.log(Level.WARNING, "Non existing factionId "+factionId+" requested! Issuing board cleaning!");
 | 
								Factions.log(Level.WARNING, "Non existing factionId "+factionId+" requested! Issuing board cleaning!");
 | 
				
			||||||
			Board.cleanAll();
 | 
								Board.clean();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return instances.get(factionId);
 | 
							return instances.get(factionId);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -415,7 +405,7 @@ public class Faction {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// purge from all boards
 | 
							// purge from all boards
 | 
				
			||||||
		// Board.purgeFactionFromAllBoards(id);
 | 
							// Board.purgeFactionFromAllBoards(id);
 | 
				
			||||||
		Board.cleanAll();
 | 
							Board.clean();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Remove the file
 | 
							// Remove the file
 | 
				
			||||||
		//File file = new File(folderFaction, id+ext);
 | 
							//File file = new File(folderFaction, id+ext);
 | 
				
			||||||
@@ -429,22 +419,4 @@ public class Faction {
 | 
				
			|||||||
		// TODO SAVE files
 | 
							// TODO SAVE files
 | 
				
			||||||
		return true; // TODO
 | 
							return true; // TODO
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	public static Faction create() {
 | 
					 | 
				
			||||||
		return EM.factionCreate();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static Faction get(Integer factionId) {
 | 
					 | 
				
			||||||
		return EM.factionGet(factionId);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static Collection<Faction> getAll() {
 | 
					 | 
				
			||||||
		return EM.factionGetAll();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public boolean save() {
 | 
					 | 
				
			||||||
		return EM.factionSave(this.id);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	*/
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,9 +39,9 @@ public class Factions extends JavaPlugin {
 | 
				
			|||||||
	.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE)
 | 
						.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE)
 | 
				
			||||||
	.create();
 | 
						.create();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private final FactionsPlayerListener playerListener = new FactionsPlayerListener(this);
 | 
						private final FactionsPlayerListener playerListener = new FactionsPlayerListener();
 | 
				
			||||||
	private final FactionsEntityListener entityListener = new FactionsEntityListener(this);
 | 
						private final FactionsEntityListener entityListener = new FactionsEntityListener();
 | 
				
			||||||
	private final FactionsBlockListener blockListener = new FactionsBlockListener(this);
 | 
						private final FactionsBlockListener blockListener = new FactionsBlockListener();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public static PermissionHandler Permissions;
 | 
						public static PermissionHandler Permissions;
 | 
				
			||||||
	public static Help helpPlugin;
 | 
						public static Help helpPlugin;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -185,7 +185,7 @@ public class FBaseCommand {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public boolean assertMinRole(Role role) {
 | 
						public boolean assertMinRole(Role role) {
 | 
				
			||||||
		if (me.role.value < role.value) {
 | 
							if (me.getRole().value < role.value) {
 | 
				
			||||||
			sendMessage("You must be "+role+" to "+this.helpDescription+".");
 | 
								sendMessage("You must be "+role+" to "+this.helpDescription+".");
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -246,13 +246,13 @@ public class FBaseCommand {
 | 
				
			|||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (i.role.value > you.role.value || i.role.equals(Role.ADMIN) ) {
 | 
							if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.ADMIN) ) {
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (you.role.equals(Role.ADMIN)) {
 | 
							if (you.getRole().equals(Role.ADMIN)) {
 | 
				
			||||||
			i.sendMessage(Conf.colorSystem+"Only the faction admin can do that.");
 | 
								i.sendMessage(Conf.colorSystem+"Only the faction admin can do that.");
 | 
				
			||||||
		} else if (i.role.equals(Role.MODERATOR)) {
 | 
							} else if (i.getRole().equals(Role.MODERATOR)) {
 | 
				
			||||||
			i.sendMessage(Conf.colorSystem+"Moderators can't control each other...");
 | 
								i.sendMessage(Conf.colorSystem+"Moderators can't control each other...");
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			i.sendMessage(Conf.colorSystem+"You must be a faction moderator to do that.");
 | 
								i.sendMessage(Conf.colorSystem+"You must be a faction moderator to do that.");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,12 +50,12 @@ public class FCommandAdmin extends FBaseCommand {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		me.role = Role.MODERATOR;
 | 
							me.setRole(Role.MODERATOR);
 | 
				
			||||||
		you.role = Role.ADMIN;
 | 
							you.setRole(Role.ADMIN);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Inform all players
 | 
							// Inform all players
 | 
				
			||||||
		for (FPlayer fplayer : FPlayer.getAllOnline()) {
 | 
							for (FPlayer fplayer : FPlayer.getAllOnline()) {
 | 
				
			||||||
			if (fplayer.factionId == me.factionId) {
 | 
								if (fplayer.getFaction() == me.getFaction()) {
 | 
				
			||||||
				fplayer.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" gave "+you.getNameAndRelevant(me)+Conf.colorSystem+" the leadership of your faction.");
 | 
									fplayer.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" gave "+you.getNameAndRelevant(me)+Conf.colorSystem+" the leadership of your faction.");
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" gave "+you.getNameAndRelevant(fplayer)+Conf.colorSystem+" the leadership of "+myFaction.getTag(fplayer));
 | 
									fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" gave "+you.getNameAndRelevant(fplayer)+Conf.colorSystem+" the leadership of "+myFaction.getTag(fplayer));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,7 +51,7 @@ public class FCommandClaim extends FBaseCommand {
 | 
				
			|||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (otherFaction.id != 0) {
 | 
							if (otherFaction.getId() != 0) {
 | 
				
			||||||
			if ( ! otherFaction.hasLandInflation()) { // TODO more messages WARN current faction most importantly
 | 
								if ( ! otherFaction.hasLandInflation()) { // TODO more messages WARN current faction most importantly
 | 
				
			||||||
				sendMessage(me.getRelationColor(otherFaction)+otherFaction.getTag()+Conf.colorSystem+" owns this land and is strong enough to keep it.");
 | 
									sendMessage(me.getRelationColor(otherFaction)+otherFaction.getTag()+Conf.colorSystem+" owns this land and is strong enough to keep it.");
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
@@ -63,7 +63,7 @@ public class FCommandClaim extends FBaseCommand {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (otherFaction.id == 0) {
 | 
							if (otherFaction.getId() == 0) {
 | 
				
			||||||
			myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D");
 | 
								myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D");
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			// ASDF claimed some of your land 450 blocks NNW of you.
 | 
								// ASDF claimed some of your land 450 blocks NNW of you.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,8 +42,8 @@ public class FCommandCreate extends FBaseCommand {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		Faction faction = Faction.create();
 | 
							Faction faction = Faction.create();
 | 
				
			||||||
		faction.setTag(tag);
 | 
							faction.setTag(tag);
 | 
				
			||||||
		me.role = Role.ADMIN;
 | 
							me.setRole(Role.ADMIN);
 | 
				
			||||||
		me.factionId = faction.id;
 | 
							me.setFaction(faction);
 | 
				
			||||||
		Faction.save();
 | 
							Faction.save();
 | 
				
			||||||
		FPlayer.save();
 | 
							FPlayer.save();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,7 +44,7 @@ public class FCommandDeinvite extends FBaseCommand {
 | 
				
			|||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		myFaction.invites.remove(you.playerName);
 | 
							myFaction.deinvite(you);
 | 
				
			||||||
		Faction.save();
 | 
							Faction.save();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" revoked your invitation to "+myFaction.getTag(you));
 | 
							you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" revoked your invitation to "+myFaction.getTag(you));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,7 +45,7 @@ public class FCommandInvite extends FBaseCommand {
 | 
				
			|||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		myFaction.invites.add(you.playerName);
 | 
							myFaction.invite(you);
 | 
				
			||||||
		Faction.save();
 | 
							Faction.save();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" invited you to "+myFaction.getTag(you));
 | 
							you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" invited you to "+myFaction.getTag(you));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,7 +28,7 @@ public class FCommandJoin extends FBaseCommand {
 | 
				
			|||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (faction.id == me.factionId) {
 | 
							if (faction == me.getFaction()) {
 | 
				
			||||||
			sendMessage("You are already a member of "+faction.getTag(me));
 | 
								sendMessage("You are already a member of "+faction.getTag(me));
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -48,8 +48,8 @@ public class FCommandJoin extends FBaseCommand {
 | 
				
			|||||||
		faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" joined your faction.");
 | 
							faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" joined your faction.");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		me.resetFactionData();
 | 
							me.resetFactionData();
 | 
				
			||||||
		me.factionId = faction.id;
 | 
							me.setFaction(faction);
 | 
				
			||||||
		faction.invites.remove(me.playerName);
 | 
							faction.deinvite(me);
 | 
				
			||||||
		FPlayer.save();
 | 
							FPlayer.save();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,12 +41,12 @@ public class FCommandKick extends FBaseCommand {
 | 
				
			|||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (you.role.value >= me.role.value) { // TODO add more informative messages.
 | 
							if (you.getRole().value >= me.getRole().value) { // TODO add more informative messages.
 | 
				
			||||||
			sendMessage("Your rank is too low to kick this player.");
 | 
								sendMessage("Your rank is too low to kick this player.");
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		myFaction.invites.remove(you.playerName);
 | 
							myFaction.deinvite(you);
 | 
				
			||||||
		you.resetFactionData();
 | 
							you.resetFactionData();
 | 
				
			||||||
		FPlayer.save();
 | 
							FPlayer.save();
 | 
				
			||||||
		Faction.save();	
 | 
							Faction.save();	
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,7 @@ public class FCommandLeave extends FBaseCommand {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		Faction faction = me.getFaction();
 | 
							Faction faction = me.getFaction();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (me.role == Role.ADMIN && faction.getFPlayers().size() > 1) {
 | 
							if (me.getRole() == Role.ADMIN && faction.getFPlayers().size() > 1) {
 | 
				
			||||||
			sendMessage("You must give the admin role to someone else first.");
 | 
								sendMessage("You must give the admin role to someone else first.");
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -41,7 +41,7 @@ public class FCommandLeave extends FBaseCommand {
 | 
				
			|||||||
			for (FPlayer fplayer : FPlayer.getAllOnline()) {
 | 
								for (FPlayer fplayer : FPlayer.getAllOnline()) {
 | 
				
			||||||
				fplayer.sendMessage("The faction "+faction.getTag(fplayer)+Conf.colorSystem+" was disbanded.");
 | 
									fplayer.sendMessage("The faction "+faction.getTag(fplayer)+Conf.colorSystem+" was disbanded.");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			Faction.delete(faction.id);
 | 
								Faction.delete(faction.getId());
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,9 +40,9 @@ public class FCommandList extends FBaseCommand {
 | 
				
			|||||||
		Collections.sort(FactionList, new Comparator<Faction>(){
 | 
							Collections.sort(FactionList, new Comparator<Faction>(){
 | 
				
			||||||
			@Override
 | 
								@Override
 | 
				
			||||||
			public int compare(Faction f1, Faction f2) {
 | 
								public int compare(Faction f1, Faction f2) {
 | 
				
			||||||
				if (f1.id == 0)
 | 
									if (f1.getId() == 0)
 | 
				
			||||||
					return 1;
 | 
										return 1;
 | 
				
			||||||
				else if (f2.id == 0)
 | 
									else if (f2.getId() == 0)
 | 
				
			||||||
					return -1;
 | 
										return -1;
 | 
				
			||||||
				else if (f1.getFPlayers().size() < f2.getFPlayers().size())
 | 
									else if (f1.getFPlayers().size() < f2.getFPlayers().size())
 | 
				
			||||||
					return 1;
 | 
										return 1;
 | 
				
			||||||
@@ -78,7 +78,7 @@ public class FCommandList extends FBaseCommand {
 | 
				
			|||||||
		if (maxPos > FactionList.size()) maxPos = FactionList.size();
 | 
							if (maxPos > FactionList.size()) maxPos = FactionList.size();
 | 
				
			||||||
		for (int pos = page * 9; pos < maxPos; pos++) {
 | 
							for (int pos = page * 9; pos < maxPos; pos++) {
 | 
				
			||||||
			Faction faction = FactionList.get(pos);
 | 
								Faction faction = FactionList.get(pos);
 | 
				
			||||||
			if (faction.id == 0) {
 | 
								if (faction.getId() == 0) {
 | 
				
			||||||
				sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size() + " online");
 | 
									sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size() + " online");
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded());
 | 
									sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,13 +49,13 @@ public class FCommandMod extends FBaseCommand {
 | 
				
			|||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (you.role == Role.MODERATOR) {
 | 
							if (you.getRole() == Role.MODERATOR) {
 | 
				
			||||||
			// Revoke
 | 
								// Revoke
 | 
				
			||||||
			you.role = Role.NORMAL;
 | 
								you.setRole(Role.NORMAL);
 | 
				
			||||||
			myFaction.sendMessage(you.getNameAndRelevant(myFaction)+Conf.colorSystem+" is no longer moderator in your faction.");
 | 
								myFaction.sendMessage(you.getNameAndRelevant(myFaction)+Conf.colorSystem+" is no longer moderator in your faction.");
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			// Give
 | 
								// Give
 | 
				
			||||||
			you.role = Role.MODERATOR;
 | 
								you.setRole(Role.MODERATOR);
 | 
				
			||||||
			myFaction.sendMessage(you.getNameAndRelevant(myFaction)+Conf.colorSystem+" was promoted to moderator in your faction.");
 | 
								myFaction.sendMessage(you.getNameAndRelevant(myFaction)+Conf.colorSystem+" was promoted to moderator in your faction.");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ public class FCommandOpen extends FBaseCommand {
 | 
				
			|||||||
		// Inform
 | 
							// Inform
 | 
				
			||||||
		myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed the faction to "+open);
 | 
							myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed the faction to "+open);
 | 
				
			||||||
		for (Faction faction : Faction.getAll()) {
 | 
							for (Faction faction : Faction.getAll()) {
 | 
				
			||||||
			if (faction.id == me.factionId) {
 | 
								if (faction == me.getFaction()) {
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			faction.sendMessage(Conf.colorSystem+"The faction "+myFaction.getTag(faction)+Conf.colorSystem+" is now "+open);
 | 
								faction.sendMessage(Conf.colorSystem+"The faction "+myFaction.getTag(faction)+Conf.colorSystem+" is now "+open);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,7 +38,7 @@ public class FCommandShow extends FBaseCommand {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		sendMessage(TextUtil.titleize(faction.getTag(me)));
 | 
							sendMessage(TextUtil.titleize(faction.getTag(me)));
 | 
				
			||||||
		sendMessage(Conf.colorChrome+"Description: "+Conf.colorSystem+faction.getDescription());
 | 
							sendMessage(Conf.colorChrome+"Description: "+Conf.colorSystem+faction.getDescription());
 | 
				
			||||||
		if (faction.id == 0) {
 | 
							if (faction.getId() == 0) {
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,7 +53,7 @@ public class FCommandTag extends FBaseCommand {
 | 
				
			|||||||
		// Inform
 | 
							// Inform
 | 
				
			||||||
		myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed your faction tag to "+Conf.colorMember+myFaction.getTag());
 | 
							myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed your faction tag to "+Conf.colorMember+myFaction.getTag());
 | 
				
			||||||
		for (Faction faction : Faction.getAll()) {
 | 
							for (Faction faction : Faction.getAll()) {
 | 
				
			||||||
			if (faction.id == me.factionId) {
 | 
								if (faction == me.getFaction()) {
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			faction.sendMessage(Conf.colorSystem+"The faction "+me.getRelationColor(faction)+oldtag+Conf.colorSystem+" chainged their name to "+myFaction.getTag(faction));
 | 
								faction.sendMessage(Conf.colorSystem+"The faction "+me.getRelationColor(faction)+oldtag+Conf.colorSystem+" chainged their name to "+myFaction.getTag(faction));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ public class FRelationCommand extends FBaseCommand {
 | 
				
			|||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (otherFaction.id == 0) {
 | 
							if (otherFaction.getId() == 0) {
 | 
				
			||||||
			sendMessage("Nope! You can't :) The default faction is not a real faction.");
 | 
								sendMessage("Nope! You can't :) The default faction is not a real faction.");
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,845 +0,0 @@
 | 
				
			|||||||
package com.bukkit.mcteam.factions.entities;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.entities.*;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.struct.*;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.util.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class CommandsOld {
 | 
					 | 
				
			||||||
	public static ArrayList<ArrayList<String>> helpPages;
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	// Build the help pages
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	static {
 | 
					 | 
				
			||||||
		helpPages = new ArrayList<ArrayList<String>>();
 | 
					 | 
				
			||||||
		ArrayList<String> pageLines;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		pageLines = new ArrayList<String>();
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasHelp, "*[page]", "Display a help page"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasList, "*[page]", "List all factions, paginated"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasShow, "*[faction name]", "Show faction information")); // TODO display relations!
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasMap, "*[on|off]", "Show territory map, set optional auto update"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasJoin, "[faction name]", "Join a faction"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasLeave, "", "Leave your faction"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasChat, "", "Switch faction only chat on and off"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasCreate, "[faction tag]", "Create new faction"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasTag, "[faction tag]", "Change the faction tag"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasDescription, "[description]", "Change the faction description"));
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		helpPages.add(pageLines);
 | 
					 | 
				
			||||||
		pageLines = new ArrayList<String>();
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasOpen, "", "Switch if invitation is required to join"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasTitle, "[player name] *[title]", "Set or remove a players title"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasInvite, "[player name]", "Invite player"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasDeinvite, "[player name]", "Remove a pending invitation"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasClaim, "", "Claim the land where you are standing"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasUnclaim, "", "Unclaim the land where you are standing"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasKick, "[player name]", "Kick a player from the faction"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasModerator, "[player name]", "Give or revoke moderator rights"));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasAdmin, "[player name]", "Hand over your admin rights"));
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		helpPages.add(pageLines);
 | 
					 | 
				
			||||||
		pageLines = new ArrayList<String>();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasRelationAlly, "[faction name]", " "));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasRelationNeutral, "[faction name]", " "));
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasRelationEnemy, "[faction name]", " "));
 | 
					 | 
				
			||||||
		pageLines.add("");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"Set the relation you WISH to have with another faction.");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"Your default relation with other factions will be neutral.");
 | 
					 | 
				
			||||||
		pageLines.add("");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"If BOTH factions choose \"ally\" you will be allies.");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"If ONE faction chooses \"enemy\" you will be enemies.");
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		helpPages.add(pageLines);
 | 
					 | 
				
			||||||
		pageLines = new ArrayList<String>();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"You can never hurt members or allies.");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"You can not hurt neutrals in their own territory.");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"You can always hurt enemies and players without faction.");
 | 
					 | 
				
			||||||
		pageLines.add("");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"Damage from enemies is reduced in your own territory.");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"When you die you lose power. It is restored over time.");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"The power of a faction is the sum of all member power.");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"The power of a faction determines how much land it can hold.");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"You can claim land from factions with too little power.");
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		helpPages.add(pageLines);
 | 
					 | 
				
			||||||
		pageLines = new ArrayList<String>();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"Only faction members can build and destroy in their own");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"territory. Usage of the following items is also restricted:");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"Door, Chest, Furnace and Dispenser.");
 | 
					 | 
				
			||||||
		pageLines.add(" ");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"Make sure to put pressure plates in front of doors for your");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"guest visitors. Otherwise they can't get through. You can ");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"also use this to create member only areas.");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"As dispensers are protected, you can create traps without");
 | 
					 | 
				
			||||||
		pageLines.add(Conf.colorSystem+"worrying about those arrows getting stolen.");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		helpPages.add(pageLines);
 | 
					 | 
				
			||||||
		pageLines = new ArrayList<String>();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		pageLines.add(TextUtil.commandHelp(Conf.aliasVersion, "", "Which version are you using?"));
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		helpPages.add(pageLines);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	// Some utils
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// Update to work with tag and follower names
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static FPlayer findFollower(FPlayer me, String name, boolean defaultsToMe) {
 | 
					 | 
				
			||||||
		if (name.length() == 0 && defaultsToMe) {
 | 
					 | 
				
			||||||
			return me;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		FPlayer follower = FPlayer.find(name);
 | 
					 | 
				
			||||||
		if (follower != null) {
 | 
					 | 
				
			||||||
			return follower;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		me.sendMessage(Conf.colorSystem+"The player \""+name+"\" could not be found");
 | 
					 | 
				
			||||||
		return null;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static Faction findFaction(FPlayer me, String name, boolean defaultsToMe) {
 | 
					 | 
				
			||||||
		if (name.length() == 0 && defaultsToMe) {
 | 
					 | 
				
			||||||
			return me.getFaction();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Search player names
 | 
					 | 
				
			||||||
		FPlayer follower = FPlayer.find(name);
 | 
					 | 
				
			||||||
		if (follower != null) {
 | 
					 | 
				
			||||||
			return follower.getFaction();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Then faction names
 | 
					 | 
				
			||||||
		Faction faction = Faction.findByTag(name);
 | 
					 | 
				
			||||||
		if (faction != null) {
 | 
					 | 
				
			||||||
			return faction;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		me.sendMessage(Conf.colorSystem+"No faction or player \""+name+"\" was found");
 | 
					 | 
				
			||||||
		return null;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static boolean canIAdministerYou(FPlayer i, FPlayer you) {
 | 
					 | 
				
			||||||
		if ( ! i.getFaction().equals(you.getFaction())) {
 | 
					 | 
				
			||||||
			i.sendMessage(you.getNameAndRelevant(i)+Conf.colorSystem+" is not in the same faction as you.");
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (i.role.value > you.role.value || i.role.equals(Role.ADMIN) ) {
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (you.role.equals(Role.ADMIN)) {
 | 
					 | 
				
			||||||
			i.sendMessage(Conf.colorSystem+"Only the faction admin can do that.");
 | 
					 | 
				
			||||||
		} else if (i.role.equals(Role.MODERATOR)) {
 | 
					 | 
				
			||||||
			i.sendMessage(Conf.colorSystem+"Moderators can't control each other...");
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			i.sendMessage(Conf.colorSystem+"You must be a faction moderator to do that.");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		return false;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	// The base command
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void base(FPlayer me, ArrayList<String> tokens) {
 | 
					 | 
				
			||||||
		if (tokens.size() == 0) {
 | 
					 | 
				
			||||||
			help(me);
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		String command = tokens.get(0).toLowerCase();
 | 
					 | 
				
			||||||
		tokens.remove(0);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (Conf.aliasHelp.contains(command)) {
 | 
					 | 
				
			||||||
			int page = 1;
 | 
					 | 
				
			||||||
			if (tokens.size() > 0) {
 | 
					 | 
				
			||||||
				try {
 | 
					 | 
				
			||||||
					page = Integer.parseInt(tokens.get(0));
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				catch (NumberFormatException e) {
 | 
					 | 
				
			||||||
					// wasn't an integer
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			help(me, page);
 | 
					 | 
				
			||||||
		} else if (Conf.aliasLeave.contains(command)) {
 | 
					 | 
				
			||||||
			leave(me);
 | 
					 | 
				
			||||||
		} else if (Conf.aliasJoin.contains(command)) {
 | 
					 | 
				
			||||||
			join(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasCreate.contains(command)) {
 | 
					 | 
				
			||||||
			create(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasTag.contains(command)) {
 | 
					 | 
				
			||||||
			tag(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasDescription.contains(command)) {
 | 
					 | 
				
			||||||
			description(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasChat.contains(command)) {
 | 
					 | 
				
			||||||
			chat(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasList.contains(command)) {
 | 
					 | 
				
			||||||
			list(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasShow.contains(command)) {
 | 
					 | 
				
			||||||
			showFaction(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasMap.contains(command)) {
 | 
					 | 
				
			||||||
			showMap(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasInvite.contains(command)) {
 | 
					 | 
				
			||||||
			invite(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasDeinvite.contains(command)) {
 | 
					 | 
				
			||||||
			deinvite(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasOpen.contains(command)) {
 | 
					 | 
				
			||||||
			open(me);
 | 
					 | 
				
			||||||
		} else if (Conf.aliasTitle.contains(command)) {
 | 
					 | 
				
			||||||
			title(me, tokens);
 | 
					 | 
				
			||||||
		} else if (Conf.aliasKick.contains(command)) {
 | 
					 | 
				
			||||||
			kick(me, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasModerator.contains(command)) {
 | 
					 | 
				
			||||||
			roleChange(me, Role.MODERATOR, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasAdmin.contains(command)) {
 | 
					 | 
				
			||||||
			roleChange(me, Role.ADMIN, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasClaim.contains(command)) {
 | 
					 | 
				
			||||||
			claim(me);
 | 
					 | 
				
			||||||
		} else if (Conf.aliasUnclaim.contains(command)) {
 | 
					 | 
				
			||||||
			unclaim(me);
 | 
					 | 
				
			||||||
		} else if (Conf.aliasRelationAlly.contains(command)) {
 | 
					 | 
				
			||||||
			relation(me, Relation.ALLY, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasRelationNeutral.contains(command)) {
 | 
					 | 
				
			||||||
			relation(me, Relation.NEUTRAL, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasRelationEnemy.contains(command)) {
 | 
					 | 
				
			||||||
			relation(me, Relation.ENEMY, TextUtil.implode(tokens));
 | 
					 | 
				
			||||||
		} else if (Conf.aliasVersion.contains(command)) {
 | 
					 | 
				
			||||||
			version(me);
 | 
					 | 
				
			||||||
		}  else {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"Unknown faction command "+Conf.colorCommand+command);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	// The other commands
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	public static void help(FPlayer me) {
 | 
					 | 
				
			||||||
		help(me, 1);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void help(FPlayer me, Integer page) {
 | 
					 | 
				
			||||||
		me.sendMessage(TextUtil.titleize("Factions Help ("+page+"/"+helpPages.size()+")"), false);
 | 
					 | 
				
			||||||
		page -= 1;
 | 
					 | 
				
			||||||
		if (page < 0 || page >= helpPages.size()) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"That page does not exist");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		me.sendMessage(helpPages.get(page), false);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	public static void leave(FPlayer me) {
 | 
					 | 
				
			||||||
		Faction faction = me.getFaction();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		ArrayList<String> errors = me.leave();
 | 
					 | 
				
			||||||
		me.sendMessage(errors);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (errors.size() == 0) {
 | 
					 | 
				
			||||||
			faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" left your faction.");
 | 
					 | 
				
			||||||
			me.sendMessage("You left "+faction.getTag(me));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (faction.getFPlayers().size() == 0) {
 | 
					 | 
				
			||||||
			// Remove this faction
 | 
					 | 
				
			||||||
			for (FPlayer follower : FPlayer.getAll()) {
 | 
					 | 
				
			||||||
				follower.sendMessage(Conf.colorSystem+"The faction "+faction.getTag(follower)+Conf.colorSystem+" was disbanded.");
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			EM.factionDelete(faction.id);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void join(FPlayer me, String name) {
 | 
					 | 
				
			||||||
		Faction faction = findFaction(me, name, false);
 | 
					 | 
				
			||||||
		if (faction == null) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		ArrayList<String> errors = me.join(faction);
 | 
					 | 
				
			||||||
		me.sendMessage(errors);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (errors.size() > 0) {
 | 
					 | 
				
			||||||
			faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" tried to join your faction.");
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You successfully joined "+faction.getTag(me));
 | 
					 | 
				
			||||||
			faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" joined your faction.");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void create(FPlayer me, String tag) {
 | 
					 | 
				
			||||||
		ArrayList<String> errors = new ArrayList<String>();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (me.hasFaction()) {
 | 
					 | 
				
			||||||
			errors.add(Conf.colorSystem+"You must leave your current faction first.");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (Faction.isTagTaken(tag)) {
 | 
					 | 
				
			||||||
			errors.add(Conf.colorSystem+"That tag is already in use.");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		errors.addAll(Faction.validateTag(tag));
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (errors.size() > 0) {
 | 
					 | 
				
			||||||
			me.sendMessage(errors);
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		Faction faction = EM.factionCreate();
 | 
					 | 
				
			||||||
		faction.setTag(tag);
 | 
					 | 
				
			||||||
		faction.save();
 | 
					 | 
				
			||||||
		me.join(faction);
 | 
					 | 
				
			||||||
		me.role = Role.ADMIN;
 | 
					 | 
				
			||||||
		me.save();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		for (FPlayer follower : FPlayer.getAll()) {
 | 
					 | 
				
			||||||
			follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" created a new faction "+faction.getTag(follower));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		me.sendMessage(Conf.colorSystem+"Now update your faction description. Use:");
 | 
					 | 
				
			||||||
		me.sendMessage(Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasDescription.get(0)+" "+"[description]");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void tag(FPlayer me, String tag) {
 | 
					 | 
				
			||||||
		ArrayList<String> errors = new ArrayList<String>();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (me.withoutFaction()) {
 | 
					 | 
				
			||||||
			errors.add(Conf.colorSystem+"You are not part of any faction");
 | 
					 | 
				
			||||||
		} else if (me.role.value < Role.MODERATOR.value) {
 | 
					 | 
				
			||||||
			errors.add(Conf.colorSystem+"You must be moderator to rename your faction");
 | 
					 | 
				
			||||||
		} 
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (Faction.isTagTaken(tag) && ! TextUtil.getComparisonString(tag).equals(me.getFaction().getComparisonTag())) {
 | 
					 | 
				
			||||||
			errors.add(Conf.colorSystem+"That tag is already taken");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		errors.addAll(Faction.validateTag(tag));
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (errors.size() > 0) {
 | 
					 | 
				
			||||||
			me.sendMessage(errors);
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		Faction myFaction = me.getFaction();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		String oldtag = myFaction.getTag();
 | 
					 | 
				
			||||||
		myFaction.setTag(tag);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Inform
 | 
					 | 
				
			||||||
		myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed your faction tag to "+Conf.colorMember+myFaction.getTag());
 | 
					 | 
				
			||||||
		for (Faction faction : Faction.getAll()) {
 | 
					 | 
				
			||||||
			if (faction.id == me.factionId) {
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			faction.sendMessage(Conf.colorSystem+"The faction "+me.getRelationColor(faction)+oldtag+Conf.colorSystem+" chainged their name to "+me.getRelationColor(faction)+myFaction.getTag());
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void list(FPlayer me, String inPage) {
 | 
					 | 
				
			||||||
		ArrayList<Faction> FactionList = new ArrayList<Faction>(Faction.getAll());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		int page = 1;
 | 
					 | 
				
			||||||
		try {
 | 
					 | 
				
			||||||
			page = Integer.parseInt(inPage);
 | 
					 | 
				
			||||||
		} catch (NumberFormatException e) {
 | 
					 | 
				
			||||||
			// wasn't an integer
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		page -= 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Sort by total followers first
 | 
					 | 
				
			||||||
		Collections.sort(FactionList, new Comparator<Faction>(){
 | 
					 | 
				
			||||||
			@Override
 | 
					 | 
				
			||||||
			public int compare(Faction f1, Faction f2) {
 | 
					 | 
				
			||||||
				if (f1.id == 0)
 | 
					 | 
				
			||||||
					return 1;
 | 
					 | 
				
			||||||
				else if (f2.id == 0)
 | 
					 | 
				
			||||||
					return -1;
 | 
					 | 
				
			||||||
				else if (f1.getFPlayers().size() < f2.getFPlayers().size())
 | 
					 | 
				
			||||||
					return 1;
 | 
					 | 
				
			||||||
				else if (f1.getFPlayers().size() > f2.getFPlayers().size())
 | 
					 | 
				
			||||||
					return -1;
 | 
					 | 
				
			||||||
				return 0;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Then sort by how many members are online now
 | 
					 | 
				
			||||||
		Collections.sort(FactionList, new Comparator<Faction>(){
 | 
					 | 
				
			||||||
			@Override
 | 
					 | 
				
			||||||
			public int compare(Faction f1, Faction f2) {
 | 
					 | 
				
			||||||
				if (f1.getFPlayersWhereOnline(true).size() < f2.getFPlayersWhereOnline(true).size())
 | 
					 | 
				
			||||||
					return 1;
 | 
					 | 
				
			||||||
				else if (f1.getFPlayersWhereOnline(true).size() > f2.getFPlayersWhereOnline(true).size())
 | 
					 | 
				
			||||||
					return -1;
 | 
					 | 
				
			||||||
				return 0;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		int maxPage = (int)Math.floor((double)FactionList.size() / 9D);
 | 
					 | 
				
			||||||
		if (page < 0 || page > maxPage) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"The faction list is only " + (maxPage+1) + " page(s) long");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		String header = "Faction List";
 | 
					 | 
				
			||||||
		if (maxPage > 1) header += " (page " + (page+1) + " of " + (maxPage+1) + ")";
 | 
					 | 
				
			||||||
		me.sendMessage(TextUtil.titleize(header), false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		int maxPos = (page+1) * 9;
 | 
					 | 
				
			||||||
		if (maxPos > FactionList.size()) maxPos = FactionList.size();
 | 
					 | 
				
			||||||
		for (int pos = page * 9; pos < maxPos; pos++) {
 | 
					 | 
				
			||||||
			Faction faction = FactionList.get(pos);
 | 
					 | 
				
			||||||
			if (faction.id == 0) {
 | 
					 | 
				
			||||||
				me.sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size() + " online");
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				me.sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded());
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void showFaction(FPlayer me, String name) {
 | 
					 | 
				
			||||||
		Faction faction = findFaction(me, name, true);
 | 
					 | 
				
			||||||
		if (faction == null) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN);
 | 
					 | 
				
			||||||
		Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
 | 
					 | 
				
			||||||
		Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		me.sendMessage(TextUtil.titleize(faction.getTag(me)), false);
 | 
					 | 
				
			||||||
		me.sendMessage(Conf.colorChrome+"Description: "+Conf.colorSystem+faction.getDescription());
 | 
					 | 
				
			||||||
		if (faction.id == 0) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if(faction.getOpen()) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorChrome+"Joining: "+Conf.colorSystem+"no invitation is needed");
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorChrome+"Joining: "+Conf.colorSystem+"invitation is required");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		me.sendMessage(Conf.colorChrome+"Land / Power / Maxpower: "+Conf.colorSystem+ faction.getLandRounded()+" / "+faction.getPowerRounded()+" / "+faction.getPowerMaxRounded());
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
		String listpart;
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// List relation
 | 
					 | 
				
			||||||
		String allyList = Conf.colorChrome+"Allies: ";
 | 
					 | 
				
			||||||
		String enemyList = Conf.colorChrome+"Enemies: ";
 | 
					 | 
				
			||||||
		for (Faction otherFaction : Faction.getAll()) {
 | 
					 | 
				
			||||||
			if (otherFaction == faction) {
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			listpart = otherFaction.getTag(me)+Conf.colorSystem+", ";
 | 
					 | 
				
			||||||
			if (otherFaction.getRelation(faction) == Relation.ALLY) {
 | 
					 | 
				
			||||||
				allyList += listpart;
 | 
					 | 
				
			||||||
			} else if (otherFaction.getRelation(faction) == Relation.ENEMY) {
 | 
					 | 
				
			||||||
				enemyList += listpart;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (allyList.endsWith(", ")) {
 | 
					 | 
				
			||||||
			allyList = allyList.substring(0, allyList.length()-2);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (enemyList.endsWith(", ")) {
 | 
					 | 
				
			||||||
			enemyList = enemyList.substring(0, enemyList.length()-2);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		me.sendMessage(allyList);
 | 
					 | 
				
			||||||
		me.sendMessage(enemyList);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// List the members...
 | 
					 | 
				
			||||||
		String onlineList = Conf.colorChrome+"Members online: ";
 | 
					 | 
				
			||||||
		String offlineList = Conf.colorChrome+"Members offline: ";
 | 
					 | 
				
			||||||
		for (FPlayer follower : admins) {
 | 
					 | 
				
			||||||
			listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", ";
 | 
					 | 
				
			||||||
			if (follower.isOnline()) {
 | 
					 | 
				
			||||||
				onlineList += listpart;
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				offlineList += listpart;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		for (FPlayer follower : mods) {
 | 
					 | 
				
			||||||
			listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", ";
 | 
					 | 
				
			||||||
			if (follower.isOnline()) {
 | 
					 | 
				
			||||||
				onlineList += listpart;
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				offlineList += listpart;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		for (FPlayer follower : normals) {
 | 
					 | 
				
			||||||
			listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", ";
 | 
					 | 
				
			||||||
			if (follower.isOnline()) {
 | 
					 | 
				
			||||||
				onlineList += listpart;
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				offlineList += listpart;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (onlineList.endsWith(", ")) {
 | 
					 | 
				
			||||||
			onlineList = onlineList.substring(0, onlineList.length()-2);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (offlineList.endsWith(", ")) {
 | 
					 | 
				
			||||||
			offlineList = offlineList.substring(0, offlineList.length()-2);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		me.sendMessage(onlineList);
 | 
					 | 
				
			||||||
		me.sendMessage(offlineList);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void showMap(FPlayer me, String mapAutoUpdating) {
 | 
					 | 
				
			||||||
		Board board = Board.get(me.getPlayer().getWorld());
 | 
					 | 
				
			||||||
		if (mapAutoUpdating.length() > 0) {
 | 
					 | 
				
			||||||
			if (Conf.aliasTrue.contains(mapAutoUpdating.toLowerCase())) {
 | 
					 | 
				
			||||||
				// Turn on
 | 
					 | 
				
			||||||
				me.setMapAutoUpdating(true);
 | 
					 | 
				
			||||||
				me.sendMessage(Conf.colorSystem + "Map auto update ENABLED.");
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
				// And show the map once
 | 
					 | 
				
			||||||
				showMap(me,"");
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				// Turn off
 | 
					 | 
				
			||||||
				me.setMapAutoUpdating(false);
 | 
					 | 
				
			||||||
				me.sendMessage(Conf.colorSystem + "Map auto update DISABLED.");
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			me.sendMessage(board.getMap(me.getFaction(), Coord.from(me), me.getPlayer().getLocation().getYaw()), false);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void invite(FPlayer me, String name) {
 | 
					 | 
				
			||||||
		FPlayer follower = findFollower(me, name, false);
 | 
					 | 
				
			||||||
		if (follower == null) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		ArrayList<String> errors = me.invite(follower);
 | 
					 | 
				
			||||||
		me.sendMessage(errors);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (errors.size() == 0) {
 | 
					 | 
				
			||||||
			follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" invited you to "+me.getFaction().getTag(follower));
 | 
					 | 
				
			||||||
			me.getFaction().sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" invited "+follower.getNameAndRelevant(me)+Conf.colorSystem+" to your faction.");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void deinvite(FPlayer me, String name) { // TODO Move out!
 | 
					 | 
				
			||||||
		FPlayer follower = findFollower(me, name, false);
 | 
					 | 
				
			||||||
		if (follower == null) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		ArrayList<String> errors = me.deinvite(follower);
 | 
					 | 
				
			||||||
		me.sendMessage(errors);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (errors.size() == 0) {
 | 
					 | 
				
			||||||
			follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" revoked your invitation to "+me.getFaction().getTag(follower));
 | 
					 | 
				
			||||||
			me.getFaction().sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" revoked "+follower.getNameAndRelevant(me)+"'s"+Conf.colorSystem+" invitation.");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void open(FPlayer me) {
 | 
					 | 
				
			||||||
		if (me.role.value < Role.MODERATOR.value) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must be moderator to do this");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		Faction myFaction = me.getFaction();
 | 
					 | 
				
			||||||
		myFaction.setOpen( ! me.getFaction().getOpen());
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		String open = myFaction.getOpen() ? "open" : "closed";
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Inform
 | 
					 | 
				
			||||||
		myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed the faction to "+open);
 | 
					 | 
				
			||||||
		for (Faction faction : Faction.getAll()) {
 | 
					 | 
				
			||||||
			if (faction.id == me.factionId) {
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			faction.sendMessage(Conf.colorSystem+"The faction "+myFaction.getTag(faction)+Conf.colorSystem+" is now "+open);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void title(FPlayer me, ArrayList<String> tokens) {
 | 
					 | 
				
			||||||
		if (tokens.size() == 0) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must specify a player name");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		String name = tokens.get(0);
 | 
					 | 
				
			||||||
		tokens.remove(0);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		FPlayer you = findFollower(me, name, true);
 | 
					 | 
				
			||||||
		if (you == null) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if ( ! canIAdministerYou(me, you)) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// All ok! Set the title!
 | 
					 | 
				
			||||||
		String title = TextUtil.implode(tokens);
 | 
					 | 
				
			||||||
		you.setTitle(title);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Inform
 | 
					 | 
				
			||||||
		Faction myFaction = me.getFaction();
 | 
					 | 
				
			||||||
		myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed a title: "+you.getNameAndRelevant(myFaction));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void kick(FPlayer me, String name) {
 | 
					 | 
				
			||||||
		if (name.length() == 0) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must specify a player name.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		FPlayer you = findFollower(me, name, false);
 | 
					 | 
				
			||||||
		if (you == null) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		ArrayList<String> errors = me.kick(you);
 | 
					 | 
				
			||||||
		me.sendMessage(errors);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (errors.size() == 0) {
 | 
					 | 
				
			||||||
			Faction myFaction = me.getFaction();
 | 
					 | 
				
			||||||
			myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" kicked "+you.getNameAndRelevant(myFaction)+Conf.colorSystem+" from the faction! :O");
 | 
					 | 
				
			||||||
			you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" kicked you from "+myFaction.getTag(you)+Conf.colorSystem+"! :O");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void roleChange(FPlayer me, Role targetRole, String name) {
 | 
					 | 
				
			||||||
		if (me.role.value < Role.ADMIN.value) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must be faction admin to do this");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (name.length() == 0) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must specify a player name.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		FPlayer targetFollower = findFollower(me, name, false);
 | 
					 | 
				
			||||||
		if (targetFollower == null) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (targetFollower.factionId != me.factionId) {
 | 
					 | 
				
			||||||
			me.sendMessage(targetFollower.getNameAndRelevant(me)+Conf.colorSystem+" is not a member in your faction.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (targetFollower == me) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"The target player musn't be yourself.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (targetRole == Role.ADMIN) {
 | 
					 | 
				
			||||||
			me.role = Role.MODERATOR;
 | 
					 | 
				
			||||||
			targetFollower.role = Role.ADMIN;
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			// Inform all players
 | 
					 | 
				
			||||||
			for (FPlayer follower : FPlayer.getAll()) {
 | 
					 | 
				
			||||||
				if (follower.factionId == me.factionId) {
 | 
					 | 
				
			||||||
					follower.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" gave "+targetFollower.getNameAndRelevant(me)+Conf.colorSystem+" the leadership of your faction.");
 | 
					 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" gave "+targetFollower.getNameAndRelevant(follower)+Conf.colorSystem+" the leadership of "+me.getFaction().getTag(follower));
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else if (targetRole == Role.MODERATOR) {
 | 
					 | 
				
			||||||
			if (targetFollower.role == Role.MODERATOR) {
 | 
					 | 
				
			||||||
				// Revoke
 | 
					 | 
				
			||||||
				targetFollower.role = Role.NORMAL;
 | 
					 | 
				
			||||||
				me.getFaction().sendMessage(targetFollower.getNameAndRelevant(me.getFaction())+Conf.colorSystem+" is no longer moderator in your faction.");
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				// Give
 | 
					 | 
				
			||||||
				targetFollower.role = Role.MODERATOR;
 | 
					 | 
				
			||||||
				me.getFaction().sendMessage(targetFollower.getNameAndRelevant(me.getFaction())+Conf.colorSystem+" was promoted to moderator in your faction.");
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void claim(FPlayer me) {
 | 
					 | 
				
			||||||
		if (me.withoutFaction()) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You are not part of any faction.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		Coord coord = Coord.from(me);
 | 
					 | 
				
			||||||
		Board board = Board.get(me.getPlayer().getWorld());
 | 
					 | 
				
			||||||
		Faction otherFaction = board.getFactionAt(coord);
 | 
					 | 
				
			||||||
		Faction myFaction = me.getFaction();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (myFaction.equals(otherFaction)) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You already own this land.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (me.role.value < Role.MODERATOR.value) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must be moderator to claim land.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You can't claim more land! You need more power!");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (otherFaction.getRelation(me) == Relation.ALLY) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You can't claim the land of your allies.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (otherFaction.id != 0) {
 | 
					 | 
				
			||||||
			if ( ! otherFaction.hasLandInflation()) { // TODO more messages WARN current faction most importantly
 | 
					 | 
				
			||||||
				me.sendMessage(me.getRelationColor(otherFaction)+otherFaction.getTag()+Conf.colorSystem+" owns this land and is strong enough to keep it.");
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			if ( ! board.isBorderCoord(coord)) {
 | 
					 | 
				
			||||||
				me.sendMessage(Conf.colorSystem+"You must start claiming land at the border of the territory.");
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (otherFaction.id == 0) {
 | 
					 | 
				
			||||||
			myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D");
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			// ASDF claimed some of your land 450 blocks NNW of you.
 | 
					 | 
				
			||||||
			// ASDf claimed some land from FACTION NAME
 | 
					 | 
				
			||||||
			otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" stole some of your land :O");
 | 
					 | 
				
			||||||
			myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some land from "+otherFaction.getTag(myFaction));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		board.claim(coord, myFaction);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void unclaim(FPlayer me) {
 | 
					 | 
				
			||||||
		if (me.withoutFaction()) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You are not part of any faction");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (me.role.value < Role.MODERATOR.value) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must be moderator to unclaim land");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		Coord coord = Coord.from(me.getPlayer());
 | 
					 | 
				
			||||||
		Board board = Board.get(me.getPlayer().getWorld());
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if ( me.getFaction() != board.getFactionAt(coord)) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You don't own this land.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		board.unclaim(coord);
 | 
					 | 
				
			||||||
		me.getFaction().sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" unclaimed some land.");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void relation(FPlayer me, Relation whishedRelation, String otherFactionName) {
 | 
					 | 
				
			||||||
		if (me.withoutFaction()) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You are not part of any faction.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (me.role.value < Role.MODERATOR.value) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must be moderator to set relation to other factions.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (otherFactionName.length() == 0) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must specify another faction.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		Faction otherFaction = findFaction(me, otherFactionName, false);
 | 
					 | 
				
			||||||
		if (otherFaction == null) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (otherFaction.id == 0) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"Nope! You can't :) The default faction is not a real faction.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (otherFaction.equals(me.getFaction())) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"Nope! You can't declare a relation to yourself :)");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		Faction myFaction = me.getFaction();
 | 
					 | 
				
			||||||
		myFaction.setRelationWish(otherFaction, whishedRelation);
 | 
					 | 
				
			||||||
		Relation currentRelation = myFaction.getRelation(otherFaction);
 | 
					 | 
				
			||||||
		ChatColor currentRelationColor = currentRelation.getColor();
 | 
					 | 
				
			||||||
		if (whishedRelation == currentRelation) {
 | 
					 | 
				
			||||||
			otherFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+myFaction.getTag());
 | 
					 | 
				
			||||||
			myFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+otherFaction.getTag());
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			otherFaction.sendMessage(currentRelationColor+myFaction.getTag()+Conf.colorSystem+ " wishes to be your "+whishedRelation.getColor()+whishedRelation.toString());
 | 
					 | 
				
			||||||
			otherFaction.sendMessage(Conf.colorSystem+"Type "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+whishedRelation+" "+myFaction.getTag()+Conf.colorSystem+" to accept.");
 | 
					 | 
				
			||||||
			myFaction.sendMessage(currentRelationColor+otherFaction.getTag()+Conf.colorSystem+ " were informed that you wish to be "+whishedRelation.getColor()+whishedRelation);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void description(FPlayer me, String desc) {
 | 
					 | 
				
			||||||
		if (me.withoutFaction()) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You are not part of any faction");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (me.role.value < Role.MODERATOR.value) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You must be moderator to set the description");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		me.getFaction().setDescription(desc);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		me.sendMessage(Conf.colorSystem+"The new description was set :D");
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Broadcast the description to everyone
 | 
					 | 
				
			||||||
		for (FPlayer follower : EM.followerGetAll()) {
 | 
					 | 
				
			||||||
			follower.sendMessage(Conf.colorSystem+"The faction "+follower.getRelationColor(me)+me.getFaction().getTag()+Conf.colorSystem+" changed their description to:");
 | 
					 | 
				
			||||||
			follower.sendMessage(Conf.colorSystem+desc);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void chat(FPlayer me, String msg) {
 | 
					 | 
				
			||||||
		if (me.withoutFaction()) {
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You are not part of any faction");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if ( ! me.isFactionChatting()) {
 | 
					 | 
				
			||||||
			// Turn on
 | 
					 | 
				
			||||||
			me.setFactionChatting(true);
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem + "Faction-only chat ENABLED.");
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			// Turn off
 | 
					 | 
				
			||||||
			me.setFactionChatting(false);
 | 
					 | 
				
			||||||
			me.sendMessage(Conf.colorSystem + "Faction-only chat DISABLED.");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void version(FPlayer me) {
 | 
					 | 
				
			||||||
		me.sendMessage(Conf.colorSystem+"You are running "+Factions.instance.getDescription().getFullName());
 | 
					 | 
				
			||||||
	}*/
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@@ -1,74 +0,0 @@
 | 
				
			|||||||
package com.bukkit.mcteam.factions.entities;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Location;
 | 
					 | 
				
			||||||
import org.bukkit.block.Block;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class CoordOld {
 | 
					 | 
				
			||||||
	protected static transient int cellSize = 16;
 | 
					 | 
				
			||||||
	public int x, z;
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public CoordOld(int x, int z) {
 | 
					 | 
				
			||||||
		this.x = x;
 | 
					 | 
				
			||||||
		this.z = z;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// TODO implements cloneable
 | 
					 | 
				
			||||||
	public CoordOld(Coord coord) {
 | 
					 | 
				
			||||||
		this.x = coord.x;
 | 
					 | 
				
			||||||
		this.z = coord.z;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public CoordOld() {
 | 
					 | 
				
			||||||
		// Noarg constructor for google gson.
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public Coord getRelative(int dx, int dz) {
 | 
					 | 
				
			||||||
		return new Coord(this.x + dx, this.z + dz);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public static Coord from(int x, int z) {
 | 
					 | 
				
			||||||
		return new Coord(x / cellSize - (x < 0 ? 1 : 0), z / cellSize - (z < 0 ? 1 : 0));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public static Coord from(Player player) {
 | 
					 | 
				
			||||||
		return from(player.getLocation());
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static Coord from(FPlayer follower) {
 | 
					 | 
				
			||||||
		return from(follower.getPlayer());
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public static Coord from(Location loc) {
 | 
					 | 
				
			||||||
		return from(loc.getBlockX(), loc.getBlockZ());
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public static Coord parseCoord(Block block) {
 | 
					 | 
				
			||||||
		return from(block.getX(), block.getZ());
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	public String toString() {
 | 
					 | 
				
			||||||
		return this.x + "," + this.z;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	public int hashCode() {
 | 
					 | 
				
			||||||
		int result = 17;
 | 
					 | 
				
			||||||
		result = 31 * result + x;
 | 
					 | 
				
			||||||
		result = 31 * result + z;
 | 
					 | 
				
			||||||
		return result;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	public boolean equals(Object obj) {
 | 
					 | 
				
			||||||
		if (obj == this)
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		if (!(obj instanceof Coord))
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		Coord o = (Coord) obj;
 | 
					 | 
				
			||||||
		return this.x == o.x && this.z == o.z;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,405 +0,0 @@
 | 
				
			|||||||
package com.bukkit.mcteam.factions.entities;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.*;
 | 
					 | 
				
			||||||
import java.lang.reflect.Modifier;
 | 
					 | 
				
			||||||
import java.util.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.World;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.Board;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.Conf;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.Faction;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.Factions;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.util.*;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.util.DiscUtil;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.gson.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * This is a entity manager that persists object to json.
 | 
					 | 
				
			||||||
 * Before using the the EM you should always EM.loadAll().
 | 
					 | 
				
			||||||
 * The methods assume that all on disc is loaded into memory.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class EMOld {
 | 
					 | 
				
			||||||
	protected static Map<String, FPlayer> followers = new HashMap<String, FPlayer>(); // Where String is a lowercase playername
 | 
					 | 
				
			||||||
	protected static Map<Integer, Faction> factions = new HashMap<Integer, Faction>(); // Where Integer is a primary auto increment key
 | 
					 | 
				
			||||||
	protected static Map<String, Board> boards = new HashMap<String, Board>(); // Where Long is the semi (sadly) unique world id.
 | 
					 | 
				
			||||||
	protected static int nextFactionId;
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// hardcoded config
 | 
					 | 
				
			||||||
	protected final static String ext = ".json";
 | 
					 | 
				
			||||||
	protected final static File folderBase = Factions.instance.getDataFolder();
 | 
					 | 
				
			||||||
	protected final static File folderFaction = new File(folderBase, "faction");
 | 
					 | 
				
			||||||
	protected final static File folderFollower = new File(folderBase, "follower");
 | 
					 | 
				
			||||||
	protected final static File folderBoard = new File(folderBase, "board");
 | 
					 | 
				
			||||||
	protected final static File fileConfig = new File(folderBase, "conf"+ext);
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public final static Gson gson = new GsonBuilder()
 | 
					 | 
				
			||||||
	.setPrettyPrinting()
 | 
					 | 
				
			||||||
	.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE)
 | 
					 | 
				
			||||||
	.registerTypeAdapter(Map.class, new MapAsArrayTypeAdapter()) // a "must have" adapter for GSON 
 | 
					 | 
				
			||||||
	.create();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public static void loadAll() {
 | 
					 | 
				
			||||||
		folderBase.mkdirs();
 | 
					 | 
				
			||||||
		configLoad();
 | 
					 | 
				
			||||||
		Log.threshold = Conf.logThreshold;
 | 
					 | 
				
			||||||
		factionLoadAll();
 | 
					 | 
				
			||||||
		followerLoadAll();
 | 
					 | 
				
			||||||
		boardLoadAll();
 | 
					 | 
				
			||||||
		Board.cleanAll();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	// Config methods (load, save)
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	public static boolean configLoad() {
 | 
					 | 
				
			||||||
		if (fileConfig.exists()) {
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				gson.fromJson(DiscUtil.read(fileConfig), Conf.class);
 | 
					 | 
				
			||||||
				Log.info("Config was loaded from disk");
 | 
					 | 
				
			||||||
				return true;
 | 
					 | 
				
			||||||
			} catch (IOException e) {
 | 
					 | 
				
			||||||
				e.printStackTrace();
 | 
					 | 
				
			||||||
				Log.warn("Failed to load the config");
 | 
					 | 
				
			||||||
				return false;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		Log.info("No conf.json found! Creating a new one with the default values");
 | 
					 | 
				
			||||||
		configSave();
 | 
					 | 
				
			||||||
		return true;		
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static boolean configSave() {
 | 
					 | 
				
			||||||
		folderBase.mkdirs();
 | 
					 | 
				
			||||||
		try {
 | 
					 | 
				
			||||||
			DiscUtil.write(fileConfig, gson.toJson(new Conf()));
 | 
					 | 
				
			||||||
			Log.debug("Config was saved to disc");
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		} catch (IOException e) {
 | 
					 | 
				
			||||||
			e.printStackTrace();
 | 
					 | 
				
			||||||
			Log.warn("Failed to save the config");
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	// Board methods (load, save)
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	/*public static boolean boardLoad() {
 | 
					 | 
				
			||||||
		if (fileBoard.exists()) {
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				gson.fromJson(DiscUtil.read(fileBoard), Board.class);
 | 
					 | 
				
			||||||
				Log.info("Board was loaded from disc");
 | 
					 | 
				
			||||||
				return true;
 | 
					 | 
				
			||||||
			} catch (IOException e) {
 | 
					 | 
				
			||||||
				e.printStackTrace();
 | 
					 | 
				
			||||||
				Log.warn("Failed to load the board");
 | 
					 | 
				
			||||||
				return false;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		Log.info("No board.json found! Creating a new one with the default values");
 | 
					 | 
				
			||||||
		boardSave();
 | 
					 | 
				
			||||||
		return true;		
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static boolean boardSave() {
 | 
					 | 
				
			||||||
		folderBase.mkdirs();
 | 
					 | 
				
			||||||
		try {
 | 
					 | 
				
			||||||
			DiscUtil.write(fileBoard, gson.toJson(new Board()));
 | 
					 | 
				
			||||||
			Log.debug("Board was saved to disc");
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		} catch (IOException e) {
 | 
					 | 
				
			||||||
			e.printStackTrace();
 | 
					 | 
				
			||||||
			Log.warn("Failed to save the board");
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}*/
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	// Board methods (loadAll, get, save)
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * This method loads all boards from disc into memory.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static void boardLoadAll() {
 | 
					 | 
				
			||||||
		Log.info("Loading all boards from disk...");
 | 
					 | 
				
			||||||
		folderBoard.mkdirs();
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
		class jsonFileFilter implements FileFilter {
 | 
					 | 
				
			||||||
			@Override
 | 
					 | 
				
			||||||
			public boolean accept(File file) {
 | 
					 | 
				
			||||||
				return (file.getName().toLowerCase().endsWith(ext) && file.isFile());
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		File[] jsonFiles = folderBoard.listFiles(new jsonFileFilter());
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		for (File jsonFile : jsonFiles) {
 | 
					 | 
				
			||||||
			// Extract the name from the filename. The name is filename minus ".json"
 | 
					 | 
				
			||||||
			String name = jsonFile.getName();
 | 
					 | 
				
			||||||
			name = name.substring(0, name.length() - ext.length());
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				Board board = gson.fromJson(DiscUtil.read(jsonFile), Board.class);
 | 
					 | 
				
			||||||
				board.worldName = name;
 | 
					 | 
				
			||||||
				boards.put(board.worldName, board);
 | 
					 | 
				
			||||||
				Log.debug("loaded board "+name);
 | 
					 | 
				
			||||||
			} catch (Exception e) {
 | 
					 | 
				
			||||||
				e.printStackTrace();
 | 
					 | 
				
			||||||
				Log.warn("failed to load board "+name);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static Collection<Board> boardGetAll() {
 | 
					 | 
				
			||||||
		return boards.values();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * This method returns the board object for a world
 | 
					 | 
				
			||||||
	 * A new Board will be created if the world did not have one
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static Board boardGet(World world) {
 | 
					 | 
				
			||||||
		if (boards.containsKey(world.getName())) {
 | 
					 | 
				
			||||||
			return boards.get(world.getName());
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		return boardCreate(world);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static boolean boardSave(String worldName) {
 | 
					 | 
				
			||||||
		Object obj = boards.get(worldName);
 | 
					 | 
				
			||||||
		if (obj == null) {
 | 
					 | 
				
			||||||
			Log.warn("Could not save board "+worldName+" as it was not loaded");
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		folderBoard.mkdirs();
 | 
					 | 
				
			||||||
		File file = new File(folderBoard, worldName+ext);
 | 
					 | 
				
			||||||
		try {
 | 
					 | 
				
			||||||
			DiscUtil.write(file, gson.toJson(obj));
 | 
					 | 
				
			||||||
			Log.debug("Saved the board "+worldName);
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		} catch (IOException e) {
 | 
					 | 
				
			||||||
			e.printStackTrace();
 | 
					 | 
				
			||||||
			Log.warn("Failed to save the board "+worldName);
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}		
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	protected static Board boardCreate(World world) {
 | 
					 | 
				
			||||||
		Log.debug("Creating new board for "+world.getName());
 | 
					 | 
				
			||||||
		Board board = new Board();
 | 
					 | 
				
			||||||
		board.worldName = world.getName();
 | 
					 | 
				
			||||||
		boards.put(board.worldName, board);
 | 
					 | 
				
			||||||
		board.save();
 | 
					 | 
				
			||||||
		return board;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	// Follower methods (loadAll, get, save)
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * This method loads all followers from disc into memory.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static void followerLoadAll() {
 | 
					 | 
				
			||||||
		Log.info("Loading all followers from disk...");
 | 
					 | 
				
			||||||
		folderFollower.mkdirs();
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
		class jsonFileFilter implements FileFilter {
 | 
					 | 
				
			||||||
			@Override
 | 
					 | 
				
			||||||
			public boolean accept(File file) {
 | 
					 | 
				
			||||||
				return (file.getName().toLowerCase().endsWith(ext) && file.isFile());
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		File[] jsonFiles = folderFollower.listFiles(new jsonFileFilter());
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		for (File jsonFile : jsonFiles) {
 | 
					 | 
				
			||||||
			// Extract the name from the filename. The name is filename minus ".json"
 | 
					 | 
				
			||||||
			String name = jsonFile.getName();
 | 
					 | 
				
			||||||
			name = name.substring(0, name.length() - ext.length());
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				FPlayer follower = gson.fromJson(DiscUtil.read(jsonFile), FPlayer.class);
 | 
					 | 
				
			||||||
				follower.id = name;
 | 
					 | 
				
			||||||
				followers.put(follower.id, follower);
 | 
					 | 
				
			||||||
				//Log.debug("loaded follower "+name);
 | 
					 | 
				
			||||||
			} catch (Exception e) {
 | 
					 | 
				
			||||||
				e.printStackTrace();
 | 
					 | 
				
			||||||
				Log.warn("failed to load follower "+name);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static Collection<FPlayer> followerGetAll() {
 | 
					 | 
				
			||||||
		return followers.values();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * This method returns the follower object for a player
 | 
					 | 
				
			||||||
	 * A new Follower will be created if the player did not have one
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static FPlayer followerGet(Player player) {
 | 
					 | 
				
			||||||
		String key = followerKey(player);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (followers.containsKey(key)) {
 | 
					 | 
				
			||||||
			return followers.get(key);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		return followerCreate(player);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static boolean followerSave(String id) {
 | 
					 | 
				
			||||||
		Object obj = followers.get(id);
 | 
					 | 
				
			||||||
		if (obj == null) {
 | 
					 | 
				
			||||||
			Log.warn("Could not save follower "+id+" as it was not loaded");
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		folderFollower.mkdirs();
 | 
					 | 
				
			||||||
		File file = new File(folderFollower, id+ext);
 | 
					 | 
				
			||||||
		try {
 | 
					 | 
				
			||||||
			DiscUtil.write(file, gson.toJson(obj));
 | 
					 | 
				
			||||||
			Log.debug("Saved the follower "+id);
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		} catch (IOException e) {
 | 
					 | 
				
			||||||
			e.printStackTrace();
 | 
					 | 
				
			||||||
			Log.warn("Failed to save the follower "+id);
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	protected static String followerKey(Player player) {
 | 
					 | 
				
			||||||
		return player.getName();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	protected static FPlayer followerCreate(Player player) {
 | 
					 | 
				
			||||||
		Log.debug("Creating new follower "+followerKey(player));
 | 
					 | 
				
			||||||
		FPlayer follower = new FPlayer();
 | 
					 | 
				
			||||||
		follower.id = followerKey(player);
 | 
					 | 
				
			||||||
		followers.put(follower.id, follower);
 | 
					 | 
				
			||||||
		follower.save();
 | 
					 | 
				
			||||||
		return follower;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	// Faction methods (loadAll, get, create, delete, save)
 | 
					 | 
				
			||||||
	//----------------------------------------------//
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * This method loads all followers from disc into memory.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static void factionLoadAll() {
 | 
					 | 
				
			||||||
		Log.info("Loading all factions from disk...");
 | 
					 | 
				
			||||||
		folderFaction.mkdirs();
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
		class jsonFileFilter implements FileFilter
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			@Override
 | 
					 | 
				
			||||||
			public boolean accept(File file) {
 | 
					 | 
				
			||||||
				return (file.getName().toLowerCase().endsWith(ext) && file.isFile());
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		nextFactionId = 0;
 | 
					 | 
				
			||||||
		File[] jsonFiles = folderFaction.listFiles(new jsonFileFilter());
 | 
					 | 
				
			||||||
		for (File jsonFile : jsonFiles) {
 | 
					 | 
				
			||||||
			// Extract the name from the filename. The name is filename minus ".json"
 | 
					 | 
				
			||||||
			String name = jsonFile.getName();
 | 
					 | 
				
			||||||
			name = name.substring(0, name.length() - ext.length());
 | 
					 | 
				
			||||||
			int id = Integer.parseInt(name);
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			// Eventually push next id forward
 | 
					 | 
				
			||||||
			if (nextFactionId < id) {
 | 
					 | 
				
			||||||
				nextFactionId = id;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				Faction faction = gson.fromJson(DiscUtil.read(jsonFile), Faction.class);
 | 
					 | 
				
			||||||
				faction.id = id;
 | 
					 | 
				
			||||||
				factions.put(faction.id, faction);
 | 
					 | 
				
			||||||
				//Log.debug("loaded faction "+id);
 | 
					 | 
				
			||||||
			} catch (Exception e) {
 | 
					 | 
				
			||||||
				e.printStackTrace();
 | 
					 | 
				
			||||||
				Log.warn("Failed to load faction "+id);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		nextFactionId += 1; // make it the next id and not the current highest.
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Make sure the default neutral faction exists
 | 
					 | 
				
			||||||
		if ( ! factions.containsKey(0)) {
 | 
					 | 
				
			||||||
			Faction faction = new Faction();
 | 
					 | 
				
			||||||
			faction.tag = "*No faction*";
 | 
					 | 
				
			||||||
			faction.description = "\"The faction for the factionless :P\"";
 | 
					 | 
				
			||||||
			faction.id = 0;
 | 
					 | 
				
			||||||
			factions.put(faction.id, faction);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static Faction factionGet(Integer factionId) {
 | 
					 | 
				
			||||||
		if ( ! factions.containsKey(factionId)) {
 | 
					 | 
				
			||||||
			Log.warn("Non existing factionId "+factionId+" requested from EM! Issuing board cleaning!");
 | 
					 | 
				
			||||||
			Board.cleanAll();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return factions.get(factionId);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static boolean factionExists(Integer factionId) {
 | 
					 | 
				
			||||||
		return factions.containsKey(factionId);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static Collection<Faction> factionGetAll() {
 | 
					 | 
				
			||||||
		return factions.values();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static Faction factionCreate() {
 | 
					 | 
				
			||||||
		Faction faction = new Faction();
 | 
					 | 
				
			||||||
		faction.id = nextFactionId;
 | 
					 | 
				
			||||||
		nextFactionId += 1;
 | 
					 | 
				
			||||||
		factions.put(faction.id, faction);
 | 
					 | 
				
			||||||
		Log.debug("created new faction "+faction.id);
 | 
					 | 
				
			||||||
		faction.save();
 | 
					 | 
				
			||||||
		return faction;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static boolean factionDelete(Integer id) {
 | 
					 | 
				
			||||||
		// NOTE that this does not do any security checks.
 | 
					 | 
				
			||||||
		// Follower might get orphaned foreign id's
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// purge from all boards
 | 
					 | 
				
			||||||
		//Board.purgeFactionFromAllBoards(id);
 | 
					 | 
				
			||||||
		Board.cleanAll();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Remove the file
 | 
					 | 
				
			||||||
		File file = new File(folderFaction, id+ext);
 | 
					 | 
				
			||||||
		file.delete();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Remove the faction
 | 
					 | 
				
			||||||
		factions.remove(id);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		return true; // TODO
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static boolean factionSave(Integer id) {
 | 
					 | 
				
			||||||
		Object obj = factions.get(id);
 | 
					 | 
				
			||||||
		if (obj == null) {
 | 
					 | 
				
			||||||
			Log.warn("Could not save faction "+id+" as it was not loaded");
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		folderFaction.mkdirs();
 | 
					 | 
				
			||||||
		File file = new File(folderFaction, id+ext);
 | 
					 | 
				
			||||||
		try {
 | 
					 | 
				
			||||||
			DiscUtil.write(file, gson.toJson(obj));
 | 
					 | 
				
			||||||
			Log.debug("saved the faction "+id);
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		} catch (IOException e) {
 | 
					 | 
				
			||||||
			e.printStackTrace();
 | 
					 | 
				
			||||||
			Log.warn("failed to save the faction "+id);
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,6 +1,9 @@
 | 
				
			|||||||
package com.bukkit.mcteam.factions.listeners;
 | 
					package com.bukkit.mcteam.factions.listeners;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.*;
 | 
					import java.util.Arrays;
 | 
				
			||||||
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					import java.util.HashSet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.block.Block;
 | 
					import org.bukkit.block.Block;
 | 
				
			||||||
@@ -13,27 +16,19 @@ import org.bukkit.event.block.BlockPlaceEvent;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.bukkit.mcteam.factions.Board;
 | 
					import com.bukkit.mcteam.factions.Board;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Conf;
 | 
					import com.bukkit.mcteam.factions.Conf;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Coord;
 | 
					import com.bukkit.mcteam.factions.FLocation;
 | 
				
			||||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
					import com.bukkit.mcteam.factions.FPlayer;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Faction;
 | 
					import com.bukkit.mcteam.factions.Faction;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Factions;
 | 
					import com.bukkit.mcteam.factions.util.TextUtil;
 | 
				
			||||||
import com.bukkit.mcteam.factions.entities.*;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.util.*;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class FactionsBlockListener extends BlockListener {
 | 
					public class FactionsBlockListener extends BlockListener {
 | 
				
			||||||
	public Factions plugin;
 | 
					 | 
				
			||||||
	public FactionsBlockListener(Factions plugin) {
 | 
					 | 
				
			||||||
		this.plugin = plugin;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void onBlockPlace(BlockPlaceEvent event) {
 | 
						public void onBlockPlace(BlockPlaceEvent event) {
 | 
				
			||||||
		// debug
 | 
					 | 
				
			||||||
		//event.getPlayer().sendMessage("Block placed: " + event.getBlockPlaced().getTypeId() + "  Block clicked: " + event.getBlock().getTypeId() + "(" + event.getBlock().getType().toString() + ")");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (event.isCancelled()) {
 | 
							if (event.isCancelled()) {
 | 
				
			||||||
			return; // Alright. lets listen to that.
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "build")) {
 | 
							if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "build")) {
 | 
				
			||||||
			event.setCancelled(true);
 | 
								event.setCancelled(true);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -60,10 +55,9 @@ public class FactionsBlockListener extends BlockListener {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public boolean playerCanBuildDestroyBlock(Player player, Block block, String action) {
 | 
						public boolean playerCanBuildDestroyBlock(Player player, Block block, String action) {
 | 
				
			||||||
		Coord coord = Coord.parseCoord(block);
 | 
							Faction otherFaction = Board.getFactionAt(new FLocation(block));
 | 
				
			||||||
		Faction otherFaction = Board.get(player.getWorld()).getFactionAt(coord);
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (otherFaction == null || otherFaction.id == 0) {
 | 
							if (otherFaction == null || otherFaction.getId() == 0) {
 | 
				
			||||||
			return true; // This is no faction territory. You may build or break stuff here.
 | 
								return true; // This is no faction territory. You may build or break stuff here.
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@@ -72,8 +66,7 @@ public class FactionsBlockListener extends BlockListener {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// Cancel if we are not in our own territory
 | 
							// Cancel if we are not in our own territory
 | 
				
			||||||
		if (myFaction != otherFaction) {
 | 
							if (myFaction != otherFaction) {
 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You can't "+action+" in the territory of "+otherFaction.getTag(myFaction));
 | 
								me.sendMessage("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction));
 | 
				
			||||||
			//otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" tried to "+action+" "+TextUtil.getMaterialName(block.getType())+" in your territory");
 | 
					 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@@ -83,7 +76,7 @@ public class FactionsBlockListener extends BlockListener {
 | 
				
			|||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void onBlockInteract(BlockInteractEvent event) {
 | 
						public void onBlockInteract(BlockInteractEvent event) {
 | 
				
			||||||
		if (event.isCancelled()) {
 | 
							if (event.isCancelled()) {
 | 
				
			||||||
			return; // Alright. lets listen to that.
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if ( ! (event.getEntity() instanceof Player)) {
 | 
							if ( ! (event.getEntity() instanceof Player)) {
 | 
				
			||||||
@@ -94,9 +87,6 @@ public class FactionsBlockListener extends BlockListener {
 | 
				
			|||||||
		Block block = event.getBlock();
 | 
							Block block = event.getBlock();
 | 
				
			||||||
		Player player = (Player) event.getEntity();
 | 
							Player player = (Player) event.getEntity();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// debug
 | 
					 | 
				
			||||||
		//player.sendMessage("Block interacted: " + event.getBlock().getTypeId() + "(" + event.getBlock().getType().toString() + ")");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if ( ! canPlayerUseRightclickBlock(player, block)) {
 | 
							if ( ! canPlayerUseRightclickBlock(player, block)) {
 | 
				
			||||||
			event.setCancelled(true);
 | 
								event.setCancelled(true);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -112,10 +102,9 @@ public class FactionsBlockListener extends BlockListener {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		FPlayer me = FPlayer.get(player);
 | 
							FPlayer me = FPlayer.get(player);
 | 
				
			||||||
		Faction myFaction = me.getFaction();
 | 
							Faction myFaction = me.getFaction();
 | 
				
			||||||
		Coord blockCoord = Coord.from(block.getLocation());
 | 
							Faction otherFaction = Board.getFactionAt(new FLocation(block));
 | 
				
			||||||
		Faction otherFaction = Board.get(player.getWorld()).getFactionAt(blockCoord);
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (otherFaction != null && otherFaction.id != 0 && myFaction != otherFaction) {
 | 
							if (otherFaction != null && otherFaction.getId() != 0 && myFaction != otherFaction) {
 | 
				
			||||||
			me.sendMessage(Conf.colorSystem+"You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction));
 | 
								me.sendMessage(Conf.colorSystem+"You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction));
 | 
				
			||||||
			//otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" tried to use "+TextUtil.getMaterialName(material)+" in your territory");
 | 
								//otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" tried to use "+TextUtil.getMaterialName(material)+" in your territory");
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,9 +3,9 @@ package com.bukkit.mcteam.factions.listeners;
 | 
				
			|||||||
import java.text.MessageFormat;
 | 
					import java.text.MessageFormat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Creeper;
 | 
				
			||||||
import org.bukkit.entity.Entity;
 | 
					import org.bukkit.entity.Entity;
 | 
				
			||||||
import org.bukkit.entity.Fireball;
 | 
					import org.bukkit.entity.Fireball;
 | 
				
			||||||
import org.bukkit.entity.LivingEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
 | 
					import org.bukkit.event.entity.EntityDamageByEntityEvent;
 | 
				
			||||||
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
 | 
					import org.bukkit.event.entity.EntityDamageByProjectileEvent;
 | 
				
			||||||
@@ -16,16 +16,11 @@ import org.bukkit.event.entity.EntityListener;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.bukkit.mcteam.factions.Board;
 | 
					import com.bukkit.mcteam.factions.Board;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Conf;
 | 
					import com.bukkit.mcteam.factions.Conf;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Coord;
 | 
					import com.bukkit.mcteam.factions.FLocation;
 | 
				
			||||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
					import com.bukkit.mcteam.factions.FPlayer;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Factions;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.struct.Relation;
 | 
					import com.bukkit.mcteam.factions.struct.Relation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class FactionsEntityListener extends EntityListener {
 | 
					public class FactionsEntityListener extends EntityListener {
 | 
				
			||||||
	public Factions plugin;
 | 
					 | 
				
			||||||
	public FactionsEntityListener(Factions plugin) {
 | 
					 | 
				
			||||||
		this.plugin = plugin;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void onEntityDeath(EntityDeathEvent event) {
 | 
						public void onEntityDeath(EntityDeathEvent event) {
 | 
				
			||||||
@@ -37,7 +32,7 @@ public class FactionsEntityListener extends EntityListener {
 | 
				
			|||||||
		Player player = (Player) entity;
 | 
							Player player = (Player) entity;
 | 
				
			||||||
		FPlayer follower = FPlayer.get(player);
 | 
							FPlayer follower = FPlayer.get(player);
 | 
				
			||||||
		follower.onDeath();
 | 
							follower.onDeath();
 | 
				
			||||||
		follower.sendMessage(Conf.colorSystem+"Your power is now "+follower.getPowerRounded()+" / "+follower.getPowerMaxRounded());
 | 
							follower.sendMessage("Your power is now "+follower.getPowerRounded()+" / "+follower.getPowerMaxRounded());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -49,7 +44,7 @@ public class FactionsEntityListener extends EntityListener {
 | 
				
			|||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void onEntityDamage(EntityDamageEvent event) {
 | 
						public void onEntityDamage(EntityDamageEvent event) {
 | 
				
			||||||
		if ( event.isCancelled()) {
 | 
							if ( event.isCancelled()) {
 | 
				
			||||||
			return; // Some other plugin decided. Alright then.
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (event instanceof EntityDamageByEntityEvent) {
 | 
							if (event instanceof EntityDamageByEntityEvent) {
 | 
				
			||||||
@@ -65,24 +60,26 @@ public class FactionsEntityListener extends EntityListener {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// TODO what happens with the creeper or fireball then?
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void onEntityExplode(EntityExplodeEvent event)
 | 
						public void onEntityExplode(EntityExplodeEvent event)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (Conf.territoryBlockCreepers && event.getEntity() instanceof LivingEntity)
 | 
							if ( event.isCancelled()) {
 | 
				
			||||||
		{	// creeper which might need prevention, if inside faction territory
 | 
								return;
 | 
				
			||||||
			if (Board.get(event.getLocation().getWorld()).getFactionIdAt(Coord.from(event.getLocation())) > 0)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				event.setCancelled(true);
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else if (Conf.territoryBlockFireballs && event.getEntity() instanceof Fireball)
 | 
							
 | 
				
			||||||
		{	// ghast fireball which might need prevention, if inside faction territory
 | 
							// Explosions may happen in the wilderness
 | 
				
			||||||
			if (Board.get(event.getLocation().getWorld()).getFactionIdAt(Coord.from(event.getLocation())) > 0)
 | 
							if (Board.getIdAt(new FLocation(event.getLocation())) == 0) {
 | 
				
			||||||
			{
 | 
								return;
 | 
				
			||||||
				event.setCancelled(true);
 | 
							}
 | 
				
			||||||
				return;
 | 
							
 | 
				
			||||||
			}
 | 
							if (Conf.territoryBlockCreepers && event.getEntity() instanceof Creeper) {
 | 
				
			||||||
 | 
								// creeper which might need prevention, if inside faction territory
 | 
				
			||||||
 | 
								event.setCancelled(true);
 | 
				
			||||||
 | 
							} else if (Conf.territoryBlockFireballs && event.getEntity() instanceof Fireball) {
 | 
				
			||||||
 | 
								// ghast fireball which might need prevention, if inside faction territory
 | 
				
			||||||
 | 
								event.setCancelled(true);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -105,7 +102,7 @@ public class FactionsEntityListener extends EntityListener {
 | 
				
			|||||||
		//Log.debug(attacker.getName() + " attacked " + defender.getName());
 | 
							//Log.debug(attacker.getName() + " attacked " + defender.getName());
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Players without faction may be hurt anywhere
 | 
							// Players without faction may be hurt anywhere
 | 
				
			||||||
		if (defender.factionId == 0) {
 | 
							if (defender.getFaction().getId() == 0) {
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,22 +12,14 @@ import org.bukkit.event.player.PlayerListener;
 | 
				
			|||||||
import org.bukkit.event.player.PlayerMoveEvent;
 | 
					import org.bukkit.event.player.PlayerMoveEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.bukkit.mcteam.factions.Board;
 | 
					import com.bukkit.mcteam.factions.Board;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Commands;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.Conf;
 | 
					import com.bukkit.mcteam.factions.Conf;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Coord;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
					import com.bukkit.mcteam.factions.FPlayer;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Faction;
 | 
					import com.bukkit.mcteam.factions.Faction;
 | 
				
			||||||
import com.bukkit.mcteam.factions.Factions;
 | 
					import com.bukkit.mcteam.factions.Factions;
 | 
				
			||||||
import com.bukkit.mcteam.factions.entities.*;
 | 
					 | 
				
			||||||
import com.bukkit.mcteam.factions.util.TextUtil;
 | 
					import com.bukkit.mcteam.factions.util.TextUtil;
 | 
				
			||||||
import com.bukkit.mcteam.factions.util.Log;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class FactionsPlayerListener extends PlayerListener{
 | 
					public class FactionsPlayerListener extends PlayerListener{
 | 
				
			||||||
	public Factions plugin;
 | 
					 | 
				
			||||||
	public FactionsPlayerListener(Factions plugin) {
 | 
					 | 
				
			||||||
		this.plugin = plugin;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * If someone says something that starts with the factions base command
 | 
						 * If someone says something that starts with the factions base command
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user