Safe zones and faction homes :D :D
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
name: Factions
 | 
			
		||||
version: 1.1
 | 
			
		||||
version: 1.1 alpha
 | 
			
		||||
main: com.bukkit.mcteam.factions.Factions
 | 
			
		||||
commands:
 | 
			
		||||
  f:
 | 
			
		||||
 
 | 
			
		||||
@@ -126,8 +126,10 @@ public class Board {
 | 
			
		||||
				} else {
 | 
			
		||||
					FLocation flocationHere = topLeft.getRelative(dx, dz);
 | 
			
		||||
					Faction factionHere = getFactionAt(flocationHere);
 | 
			
		||||
					if (factionHere.getId() == 0) {
 | 
			
		||||
					if (factionHere.isNone()) {
 | 
			
		||||
						row += ChatColor.GRAY+"-";
 | 
			
		||||
					} else if (factionHere.isSafeZone()) {
 | 
			
		||||
						row += ChatColor.GOLD+"+";
 | 
			
		||||
					} else {
 | 
			
		||||
						row += factionHere.getRelation(faction).getColor()+"+";
 | 
			
		||||
					}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ import java.io.File;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import org.bukkit.*;
 | 
			
		||||
import org.bukkit.entity.CreatureType;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.util.DiscUtil;
 | 
			
		||||
 | 
			
		||||
@@ -42,8 +43,12 @@ public class Conf {
 | 
			
		||||
	public static String chatTagFormat = "%s"+ChatColor.WHITE+" ";
 | 
			
		||||
	public static String factionChatFormat = "%s"+ChatColor.WHITE+" %s";
 | 
			
		||||
	
 | 
			
		||||
	public static int mapHeight = 8;
 | 
			
		||||
	public static int mapWidth = 49;
 | 
			
		||||
	public static boolean allowNoSlashCommand = true;
 | 
			
		||||
	
 | 
			
		||||
	public static double autoLeaveAfterDaysOfInactivity = 14;
 | 
			
		||||
	
 | 
			
		||||
	public static boolean homesEnabled = true;
 | 
			
		||||
	public static boolean homesTeleportToOnDeath = true;
 | 
			
		||||
 | 
			
		||||
	public static double territoryShieldFactor = 0.5;
 | 
			
		||||
	public static boolean territoryBlockCreepers = false;
 | 
			
		||||
@@ -51,11 +56,12 @@ public class Conf {
 | 
			
		||||
	
 | 
			
		||||
	public static Set<Material> territoryProtectedMaterials = new HashSet<Material>();
 | 
			
		||||
	public static Set<Material> territoryDenyUseageMaterials = new HashSet<Material>();
 | 
			
		||||
	
 | 
			
		||||
	public static transient Set<CreatureType> safeZoneNerfedCreatureTypes = new HashSet<CreatureType>();
 | 
			
		||||
	
 | 
			
		||||
	public static transient Set<Material> instaDestroyMaterials = new HashSet<Material>(); // This one is not really configuration therefore transient
 | 
			
		||||
 | 
			
		||||
	public static boolean allowNoSlashCommand = true;
 | 
			
		||||
	
 | 
			
		||||
	public static double autoLeaveFactionAfterDaysOfInactivity = 14;
 | 
			
		||||
	public static transient int mapHeight = 8;
 | 
			
		||||
	public static transient int mapWidth = 49;
 | 
			
		||||
	
 | 
			
		||||
	static {
 | 
			
		||||
		territoryProtectedMaterials.add(Material.WOODEN_DOOR);
 | 
			
		||||
@@ -81,6 +87,14 @@ public class Conf {
 | 
			
		||||
		instaDestroyMaterials.add(Material.SUGAR_CANE_BLOCK);
 | 
			
		||||
		instaDestroyMaterials.add(Material.DIODE_BLOCK_OFF);
 | 
			
		||||
		instaDestroyMaterials.add(Material.DIODE_BLOCK_ON);
 | 
			
		||||
		
 | 
			
		||||
		safeZoneNerfedCreatureTypes.add(CreatureType.CREEPER);
 | 
			
		||||
		safeZoneNerfedCreatureTypes.add(CreatureType.GHAST);
 | 
			
		||||
		safeZoneNerfedCreatureTypes.add(CreatureType.PIG_ZOMBIE);
 | 
			
		||||
		safeZoneNerfedCreatureTypes.add(CreatureType.SKELETON);
 | 
			
		||||
		safeZoneNerfedCreatureTypes.add(CreatureType.SPIDER);
 | 
			
		||||
		safeZoneNerfedCreatureTypes.add(CreatureType.SLIME);
 | 
			
		||||
		safeZoneNerfedCreatureTypes.add(CreatureType.ZOMBIE);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 
 | 
			
		||||
@@ -353,7 +353,7 @@ public class FPlayer {
 | 
			
		||||
	public void sendFactionHereMessage() {
 | 
			
		||||
		Faction factionHere = Board.getFactionAt(new FLocation(this));
 | 
			
		||||
		String msg = Conf.colorSystem+" ~ "+factionHere.getTag(this);
 | 
			
		||||
		if (factionHere.getId() != 0) {
 | 
			
		||||
		if (factionHere.getDescription().length() > 0) {
 | 
			
		||||
			msg += " - "+factionHere.getDescription();
 | 
			
		||||
		}
 | 
			
		||||
		this.sendMessage(msg);
 | 
			
		||||
@@ -507,9 +507,16 @@ public class FPlayer {
 | 
			
		||||
	
 | 
			
		||||
	public static void autoLeaveOnInactivityRoutine() {
 | 
			
		||||
		long now = System.currentTimeMillis();
 | 
			
		||||
		double toleranceMillis = Conf.autoLeaveFactionAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
 | 
			
		||||
		double toleranceMillis = Conf.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
 | 
			
		||||
		
 | 
			
		||||
		for (FPlayer fplayer : FPlayer.getAll()) {
 | 
			
		||||
			// Test if the player is immune
 | 
			
		||||
			if (Factions.Permissions != null) {
 | 
			
		||||
				if (Factions.Permissions.has(fplayer.getPlayer(), "factions.autoLeaveImmunity")) {
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			if (now - fplayer.getLastLoginTime() > toleranceMillis) {
 | 
			
		||||
				fplayer.leave();
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ import java.util.Map.Entry;
 | 
			
		||||
import java.util.logging.Level;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Relation;
 | 
			
		||||
@@ -32,6 +33,7 @@ public class Faction {
 | 
			
		||||
	private boolean open;
 | 
			
		||||
	private String tag;
 | 
			
		||||
	private String description;
 | 
			
		||||
	private Location home;
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// Construct
 | 
			
		||||
@@ -88,6 +90,34 @@ public class Faction {
 | 
			
		||||
		this.description = value;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void setHome(Location home) {
 | 
			
		||||
		this.home = home;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Location getHome() {
 | 
			
		||||
		return home;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public boolean hasHome() {
 | 
			
		||||
		return this.home != null;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------
 | 
			
		||||
	// Understand the types
 | 
			
		||||
	// -------------------------------
 | 
			
		||||
	
 | 
			
		||||
	public boolean isNormal() {
 | 
			
		||||
		return this.getId() > 0;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public boolean isNone() {
 | 
			
		||||
		return this.getId() == 0;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public boolean isSafeZone() {
 | 
			
		||||
		return this.getId() == -1;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------
 | 
			
		||||
	// Invites - uses lowercase name
 | 
			
		||||
	// -------------------------------
 | 
			
		||||
@@ -124,7 +154,7 @@ public class Faction {
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public Relation getRelation(Faction otherFaction) {
 | 
			
		||||
		if (otherFaction.getId() == 0 || this.getId() == 0) {
 | 
			
		||||
		if (otherFaction.isNone() || this.isNone()) {
 | 
			
		||||
			return Relation.NEUTRAL;
 | 
			
		||||
		}
 | 
			
		||||
		if (otherFaction.equals(this)) {
 | 
			
		||||
@@ -340,6 +370,15 @@ public class Faction {
 | 
			
		||||
			instances.put(faction.id, faction);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// Make sure the safe zone faciton exists
 | 
			
		||||
		if ( ! instances.containsKey(-1)) {
 | 
			
		||||
			Faction faction = new Faction();
 | 
			
		||||
			faction.tag = ChatColor.GOLD+"Safe Zone";
 | 
			
		||||
			faction.description = "Free from PVP and monsters";
 | 
			
		||||
			faction.id = -1;
 | 
			
		||||
			instances.put(faction.id, faction);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
@@ -363,6 +402,14 @@ public class Faction {
 | 
			
		||||
		return instances.get(factionId);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static Faction getNone() {
 | 
			
		||||
		return instances.get(0);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static Faction getSafeZone() {
 | 
			
		||||
		return instances.get(-1);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static boolean exists(Integer factionId) {
 | 
			
		||||
		return instances.containsKey(factionId);
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,8 +10,10 @@ import java.util.logging.Logger;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.Event;
 | 
			
		||||
import org.bukkit.plugin.Plugin;
 | 
			
		||||
import org.bukkit.plugin.PluginManager;
 | 
			
		||||
@@ -25,6 +27,7 @@ import com.bukkit.mcteam.factions.commands.FCommandCreate;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandDeinvite;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandDescription;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandHelp;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandHome;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandInvite;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandJoin;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandKick;
 | 
			
		||||
@@ -36,6 +39,8 @@ import com.bukkit.mcteam.factions.commands.FCommandOpen;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandRelationAlly;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandRelationEnemy;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandRelationNeutral;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandSafeclaim;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandSethome;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandShow;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandTag;
 | 
			
		||||
import com.bukkit.mcteam.factions.commands.FCommandTitle;
 | 
			
		||||
@@ -64,6 +69,7 @@ public class Factions extends JavaPlugin {
 | 
			
		||||
	public final static Gson gson = new GsonBuilder()
 | 
			
		||||
	.setPrettyPrinting()
 | 
			
		||||
	.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE)
 | 
			
		||||
	.registerTypeAdapter(Location.class, new MyLocationTypeAdapter())
 | 
			
		||||
	.create();
 | 
			
		||||
	
 | 
			
		||||
	private final FactionsPlayerListener playerListener = new FactionsPlayerListener();
 | 
			
		||||
@@ -96,6 +102,7 @@ public class Factions extends JavaPlugin {
 | 
			
		||||
		commands.add(new FCommandCreate());
 | 
			
		||||
		commands.add(new FCommandDeinvite());
 | 
			
		||||
		commands.add(new FCommandDescription());
 | 
			
		||||
		commands.add(new FCommandHome());
 | 
			
		||||
		commands.add(new FCommandInvite());
 | 
			
		||||
		commands.add(new FCommandJoin());
 | 
			
		||||
		commands.add(new FCommandKick());
 | 
			
		||||
@@ -107,6 +114,8 @@ public class Factions extends JavaPlugin {
 | 
			
		||||
		commands.add(new FCommandRelationAlly());
 | 
			
		||||
		commands.add(new FCommandRelationEnemy());
 | 
			
		||||
		commands.add(new FCommandRelationNeutral());
 | 
			
		||||
		commands.add(new FCommandSafeclaim());
 | 
			
		||||
		commands.add(new FCommandSethome());
 | 
			
		||||
		commands.add(new FCommandShow());
 | 
			
		||||
		commands.add(new FCommandTag());
 | 
			
		||||
		commands.add(new FCommandTitle());
 | 
			
		||||
@@ -127,14 +136,15 @@ public class Factions extends JavaPlugin {
 | 
			
		||||
		// Register events
 | 
			
		||||
		PluginManager pm = this.getServer().getPluginManager();
 | 
			
		||||
		pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.PLAYER_ITEM, this.playerListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Event.Priority.High, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.ENTITY_DAMAGED, this.entityListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.ENTITY_TARGET, this.entityListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.BLOCK_DAMAGED, this.blockListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.BLOCK_PLACED, this.blockListener, Event.Priority.Normal, this);
 | 
			
		||||
		pm.registerEvent(Event.Type.BLOCK_INTERACT, this.blockListener, Event.Priority.Normal, this);
 | 
			
		||||
@@ -156,21 +166,6 @@ public class Factions extends JavaPlugin {
 | 
			
		||||
	// Integration with other plugins
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	private void setupPermissions() {
 | 
			
		||||
		if (Permissions != null) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
 | 
			
		||||
		
 | 
			
		||||
		if (test != null) {
 | 
			
		||||
			Permissions = ((Permissions)test).getHandler();
 | 
			
		||||
			Factions.log("Found and will use plugin "+((Permissions)test).getDescription().getFullName());
 | 
			
		||||
		} else {
 | 
			
		||||
			Factions.log("Permission system not detected, defaulting to OP");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void setupHelp() {
 | 
			
		||||
		if (helpPlugin != null) {
 | 
			
		||||
			return;
 | 
			
		||||
@@ -186,6 +181,53 @@ public class Factions extends JavaPlugin {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void setupPermissions() {
 | 
			
		||||
		if (Permissions != null) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
 | 
			
		||||
		
 | 
			
		||||
		if (test != null) {
 | 
			
		||||
			Permissions = ((Permissions)test).getHandler();
 | 
			
		||||
			Factions.log("Found and will use plugin "+((Permissions)test).getDescription().getFullName());
 | 
			
		||||
		} else {
 | 
			
		||||
			Factions.log("Permission system not detected, defaulting to OP");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// Test rights
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public static boolean hasPermParticipate(CommandSender sender) {
 | 
			
		||||
		return hasPerm(sender, "factions.participate", false);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static boolean hasPermCreate(CommandSender sender) {
 | 
			
		||||
		return hasPerm(sender, "factions.create", false);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static boolean hasPermManageSafeZone(CommandSender sender) {
 | 
			
		||||
		return hasPerm(sender, "factions.manageSafeZone", true);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static boolean hasPermAutoLeaveImmunity(CommandSender sender) {
 | 
			
		||||
		return hasPerm(sender, "factions.autoLeaveImmunity", true);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private static boolean hasPerm(CommandSender sender, String permNode, boolean fallbackOnlyOp) {
 | 
			
		||||
		if (Factions.Permissions == null || ! (sender instanceof Player)) {
 | 
			
		||||
			return fallbackOnlyOp == false || sender.isOp();
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (sender instanceof Player) {
 | 
			
		||||
			Player player = (Player)sender;
 | 
			
		||||
			return Factions.Permissions.has(player, permNode); 
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// Commands
 | 
			
		||||
@@ -247,6 +289,7 @@ public class Factions extends JavaPlugin {
 | 
			
		||||
		FPlayer.save();
 | 
			
		||||
		Faction.save();
 | 
			
		||||
		Board.save();
 | 
			
		||||
		Conf.save();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										51
									
								
								src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
package com.bukkit.mcteam.factions;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Type;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.World;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.gson.JsonDeserializationContext;
 | 
			
		||||
import com.bukkit.mcteam.gson.JsonDeserializer;
 | 
			
		||||
import com.bukkit.mcteam.gson.JsonElement;
 | 
			
		||||
import com.bukkit.mcteam.gson.JsonObject;
 | 
			
		||||
import com.bukkit.mcteam.gson.JsonParseException;
 | 
			
		||||
import com.bukkit.mcteam.gson.JsonSerializationContext;
 | 
			
		||||
import com.bukkit.mcteam.gson.JsonSerializer;
 | 
			
		||||
 | 
			
		||||
public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSerializer<Location> {
 | 
			
		||||
	private static final String WORLD = "world";
 | 
			
		||||
	private static final String X = "x";
 | 
			
		||||
	private static final String Y = "y";
 | 
			
		||||
	private static final String Z = "z";
 | 
			
		||||
	private static final String YAW = "yaw";
 | 
			
		||||
	private static final String PITCH = "pitch";
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
 | 
			
		||||
		JsonObject obj = json.getAsJsonObject();
 | 
			
		||||
		
 | 
			
		||||
		World world = Factions.instance.getServer().getWorld(obj.get(WORLD).getAsString());
 | 
			
		||||
		double x = obj.get(X).getAsDouble();
 | 
			
		||||
		double y = obj.get(Y).getAsDouble();
 | 
			
		||||
		double z = obj.get(Z).getAsDouble();
 | 
			
		||||
		float yaw = obj.get(YAW).getAsFloat();
 | 
			
		||||
		float pitch = obj.get(PITCH).getAsFloat();
 | 
			
		||||
		
 | 
			
		||||
		return new Location(world, x, y, z, yaw, pitch);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public JsonElement serialize(Location src, Type typeOfSrc, JsonSerializationContext context) {
 | 
			
		||||
		JsonObject obj = new JsonObject();
 | 
			
		||||
		
 | 
			
		||||
		obj.addProperty(WORLD, src.getWorld().getName());
 | 
			
		||||
		obj.addProperty(X, src.getX());
 | 
			
		||||
		obj.addProperty(Y, src.getY());
 | 
			
		||||
		obj.addProperty(Z, src.getZ());
 | 
			
		||||
		obj.addProperty(YAW, src.getYaw());
 | 
			
		||||
		obj.addProperty(PITCH, src.getPitch());
 | 
			
		||||
		
 | 
			
		||||
		return obj;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -15,12 +15,9 @@ import com.bukkit.mcteam.factions.util.TextUtil;
 | 
			
		||||
 | 
			
		||||
public class FBaseCommand {
 | 
			
		||||
	public List<String> aliases;
 | 
			
		||||
	
 | 
			
		||||
	public List<String> requiredParameters;
 | 
			
		||||
	public List<String> optionalParameters;
 | 
			
		||||
	
 | 
			
		||||
	public String permissions;
 | 
			
		||||
	
 | 
			
		||||
	public String helpNameAndParams;
 | 
			
		||||
	public String helpDescription;
 | 
			
		||||
	
 | 
			
		||||
@@ -33,12 +30,11 @@ public class FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	public FBaseCommand() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = false;
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpNameAndParams = "fail!";
 | 
			
		||||
		helpDescription = "no description";
 | 
			
		||||
@@ -48,11 +44,6 @@ public class FBaseCommand {
 | 
			
		||||
		return aliases;
 | 
			
		||||
	}
 | 
			
		||||
		
 | 
			
		||||
	public String getBaseName() {
 | 
			
		||||
		// TODO fetch from the plugin.yaml or something...
 | 
			
		||||
		return "f";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void execute(CommandSender sender, List<String> parameters) {
 | 
			
		||||
		this.sender = sender;
 | 
			
		||||
		this.parameters = parameters;
 | 
			
		||||
@@ -83,16 +74,14 @@ public class FBaseCommand {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// Test if the number of params is correct.
 | 
			
		||||
	// TODO print usage
 | 
			
		||||
	public boolean validateCall() {
 | 
			
		||||
		if( ! testPermission(sender)) {
 | 
			
		||||
			sendMessage("You do not have sufficient permissions to use this command.");
 | 
			
		||||
		if ( this.senderMustBePlayer && ! (sender instanceof Player)) {
 | 
			
		||||
			sendMessage("This command can only be used by ingame players.");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( this.senderMustBePlayer && ! (sender instanceof Player)) {
 | 
			
		||||
			sendMessage("This command can only be used by ingame players.");
 | 
			
		||||
		if( ! hasPermission(sender)) {
 | 
			
		||||
			sendMessage("You lack the permissions to "+this.helpDescription.toLowerCase()+".");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
@@ -104,26 +93,29 @@ public class FBaseCommand {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public boolean testPermission(CommandSender sender) {
 | 
			
		||||
		if (sender.isOp()) {
 | 
			
		||||
			return true;
 | 
			
		||||
	public boolean hasPermission(CommandSender sender) {
 | 
			
		||||
		return Factions.hasPermParticipate(sender);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/*public boolean testPermission(CommandSender sender) {
 | 
			
		||||
		// There are two cases where we default to op:
 | 
			
		||||
		// 1. Permissions is not installed
 | 
			
		||||
		// 2. The sender is not a player
 | 
			
		||||
		if ( Factions.Permissions == null || (! (sender instanceof Player))) {
 | 
			
		||||
			if (this.opOnly && sender.isOp()) {
 | 
			
		||||
				return true;
 | 
			
		||||
			}
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// No permissions are needed to use this command.
 | 
			
		||||
		if (this.permissions.length() == 0) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( ! (sender instanceof Player)) {
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (Factions.Permissions == null) {
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		Player player = (Player)sender;
 | 
			
		||||
		return Factions.Permissions.has(player, this.permissions);		
 | 
			
		||||
	}
 | 
			
		||||
	}*/
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// Help and usage description
 | 
			
		||||
@@ -135,7 +127,7 @@ public class FBaseCommand {
 | 
			
		||||
			ret += Conf.colorCommand;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		ret += this.getBaseName()+ " " +TextUtil.implode(this.getAliases(), ",")+" ";
 | 
			
		||||
		ret += Factions.instance.getBaseCommand()+ " " +TextUtil.implode(this.getAliases(), ",")+" ";
 | 
			
		||||
		
 | 
			
		||||
		List<String> parts = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
@@ -167,10 +159,6 @@ public class FBaseCommand {
 | 
			
		||||
		return getUseageTemplate(true);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void helpRegister() {
 | 
			
		||||
		Factions.helpPlugin.registerCommand(this.getUseageTemplate(false), this.helpDescription, Factions.instance, false, permissions);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// Assertions
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
@@ -10,17 +8,10 @@ import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
public class FCommandAdmin extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandAdmin() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("admin");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("player name");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Hand over your admin rights";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,21 +1,11 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class FCommandChat extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandChat() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("chat");
 | 
			
		||||
		aliases.add("c");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Switch faction only chat on and off";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Board;
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FLocation;
 | 
			
		||||
@@ -12,16 +10,8 @@ import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
public class FCommandClaim extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandClaim() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("claim");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Claim the land where you are standing";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
@@ -54,8 +44,17 @@ public class FCommandClaim extends FBaseCommand {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (otherFaction.getId() != 0) {
 | 
			
		||||
			if ( ! otherFaction.hasLandInflation()) { // TODO more messages WARN current faction most importantly
 | 
			
		||||
		if (otherFaction.isSafeZone()) {
 | 
			
		||||
			sendMessage("You can not claim a SafeZone.");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (otherFaction.isNone()) {
 | 
			
		||||
			myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D");
 | 
			
		||||
		} else { //if (otherFaction.isNormal()) {
 | 
			
		||||
			
 | 
			
		||||
			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.");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
@@ -64,11 +63,7 @@ public class FCommandClaim extends FBaseCommand {
 | 
			
		||||
				sendMessage("You must start claiming land at the border of the territory.");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
			
 | 
			
		||||
		if (otherFaction.getId() == 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");
 | 
			
		||||
 
 | 
			
		||||
@@ -2,28 +2,29 @@ package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
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.struct.Role;
 | 
			
		||||
 | 
			
		||||
public class FCommandCreate extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandCreate() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("create");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("faction tag");
 | 
			
		||||
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Create a new faction";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean hasPermission(CommandSender sender) {
 | 
			
		||||
		return Factions.hasPermCreate(sender);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		String tag = parameters.get(0);
 | 
			
		||||
		
 | 
			
		||||
@@ -52,8 +53,7 @@ public class FCommandCreate extends FBaseCommand {
 | 
			
		||||
			follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" created a new faction "+faction.getTag(follower));
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		sendMessage("You should now:");
 | 
			
		||||
		sendMessage( new FCommandDescription().getUseageTemplate() );
 | 
			
		||||
		sendMessage("You should now: " + new FCommandDescription().getUseageTemplate(true, true));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
@@ -10,18 +8,11 @@ import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
public class FCommandDeinvite extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandDeinvite() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("deinvite");
 | 
			
		||||
		aliases.add("deinv");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("player name");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Remove a pending invitation";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
@@ -10,17 +8,10 @@ import com.bukkit.mcteam.factions.util.TextUtil;
 | 
			
		||||
public class FCommandDescription extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandDescription() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("desc");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("desc");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Change the faction description";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -2,28 +2,27 @@ package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.util.TextUtil;
 | 
			
		||||
 | 
			
		||||
public class FCommandHelp extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandHelp() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("help");
 | 
			
		||||
		aliases.add("h");
 | 
			
		||||
		aliases.add("?");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters.add("page");		
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = false;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Display a help page";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean hasPermission(CommandSender sender) {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		int page = 1;
 | 
			
		||||
		if (parameters.size() > 0) {
 | 
			
		||||
@@ -60,67 +59,74 @@ public class FCommandHelp extends FBaseCommand {
 | 
			
		||||
		pageLines.add( new FCommandJoin().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandLeave().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandChat().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandCreate().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandTag().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandDescription().getUseageTemplate(true, true) );
 | 
			
		||||
		
 | 
			
		||||
		pageLines.add( new FCommandHome().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( "Learn how to create a faction on the next page." );
 | 
			
		||||
		helpPages.add(pageLines);
 | 
			
		||||
		pageLines = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		pageLines = new ArrayList<String>();
 | 
			
		||||
		pageLines.add( "Create a faction using these two commands:" );
 | 
			
		||||
		pageLines.add( new FCommandCreate().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandDescription().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( "You might wan't to close it and use invitations:" );
 | 
			
		||||
		pageLines.add( new FCommandOpen().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandTitle().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandInvite().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandDeinvite().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( "And don't forget to set your home:" );
 | 
			
		||||
		pageLines.add( new FCommandSethome().getUseageTemplate(true, true) );
 | 
			
		||||
		helpPages.add(pageLines);
 | 
			
		||||
		
 | 
			
		||||
		pageLines = new ArrayList<String>();
 | 
			
		||||
		pageLines.add( "Faction can claim land that will be protected." );
 | 
			
		||||
		pageLines.add( new FCommandClaim().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandUnclaim().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandTag().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandKick().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandMod().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandAdmin().getUseageTemplate(true, true) );
 | 
			
		||||
		
 | 
			
		||||
		pageLines.add( new FCommandTitle().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( "Player titles are just for fun. No rules connected to them." );
 | 
			
		||||
		helpPages.add(pageLines);
 | 
			
		||||
		pageLines = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		pageLines = new ArrayList<String>();
 | 
			
		||||
		pageLines.add( new FCommandRelationAlly().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandRelationNeutral().getUseageTemplate(true, true) );
 | 
			
		||||
		pageLines.add( new FCommandRelationEnemy().getUseageTemplate(true, true) );
 | 
			
		||||
		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("Set the relation you WISH to have with another faction.");
 | 
			
		||||
		pageLines.add("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.");
 | 
			
		||||
		
 | 
			
		||||
		pageLines.add("If BOTH factions choose \"ally\" you will be allies.");
 | 
			
		||||
		pageLines.add("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 = new ArrayList<String>();
 | 
			
		||||
		pageLines.add("You can never hurt members or allies.");
 | 
			
		||||
		pageLines.add("You can not hurt neutrals in their own territory.");
 | 
			
		||||
		pageLines.add("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.");
 | 
			
		||||
		
 | 
			
		||||
		pageLines.add("Damage from enemies is reduced in your own territory.");
 | 
			
		||||
		pageLines.add("When you die you lose power. It is restored over time.");
 | 
			
		||||
		pageLines.add("The power of a faction is the sum of all member power.");
 | 
			
		||||
		pageLines.add("The power of a faction determines how much land it can hold.");
 | 
			
		||||
		pageLines.add("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 = new ArrayList<String>();
 | 
			
		||||
		pageLines.add("Only faction members can build and destroy in their own");
 | 
			
		||||
		pageLines.add("territory. Usage of the following items is also restricted:");
 | 
			
		||||
		pageLines.add("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.");
 | 
			
		||||
 | 
			
		||||
		pageLines.add("Make sure to put pressure plates in front of doors for your");
 | 
			
		||||
		pageLines.add("guest visitors. Otherwise they can't get through. You can");
 | 
			
		||||
		pageLines.add("also use this to create member only areas.");
 | 
			
		||||
		pageLines.add("As dispensers are protected, you can create traps without");
 | 
			
		||||
		pageLines.add("worrying about those arrows getting stolen.");
 | 
			
		||||
		helpPages.add(pageLines);
 | 
			
		||||
		pageLines = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		pageLines = new ArrayList<String>();
 | 
			
		||||
		pageLines.add("Finally some commands for the server admins:");
 | 
			
		||||
		pageLines.add( new FCommandVersion().getUseageTemplate(true, true) );
 | 
			
		||||
		
 | 
			
		||||
		pageLines.add( new FCommandSafeclaim().getUseageTemplate(true, true) );
 | 
			
		||||
		helpPages.add(pageLines);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								src/com/bukkit/mcteam/factions/commands/FCommandHome.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/com/bukkit/mcteam/factions/commands/FCommandHome.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
 | 
			
		||||
public class FCommandHome extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandHome() {
 | 
			
		||||
		aliases.add("home");
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Teleport to the faction home";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		if ( ! assertHasFaction()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( ! Conf.homesEnabled) {
 | 
			
		||||
			me.sendMessage("Sorry, Faction homes are disabled on this server.");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		Faction myFaction = me.getFaction();
 | 
			
		||||
		
 | 
			
		||||
		if ( ! myFaction.hasHome()) {
 | 
			
		||||
			me.sendMessage("You faction does not have a home. " + (me.getRole().value < Role.MODERATOR.value ? " Ask your leader to:" : "You should:"));
 | 
			
		||||
			me.sendMessage(new FCommandSethome().getUseageTemplate(true, true));
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		player.teleportTo(myFaction.getHome());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
@@ -10,18 +8,11 @@ import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
public class FCommandInvite extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandInvite() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("invite");
 | 
			
		||||
		aliases.add("inv");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("player name");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Invite a player";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,24 +1,15 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
 | 
			
		||||
public class FCommandJoin extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandJoin() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("join");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("faction name");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Join a faction";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
@@ -30,6 +21,11 @@ public class FCommandJoin extends FBaseCommand {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if ( ! faction.isNormal()) {
 | 
			
		||||
			sendMessage("You may only join normal factions. This is a system faction.");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (faction == me.getFaction()) {
 | 
			
		||||
			sendMessage("You are already a member of "+faction.getTag(me));
 | 
			
		||||
			return;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
@@ -9,17 +7,10 @@ import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
public class FCommandKick extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandKick() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("kick");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("player name");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Kick a player from the faction";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,23 +1,20 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
public class FCommandLeave extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandLeave() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("leave");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Leave your faction";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean hasPermission(CommandSender sender) {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		if ( ! assertHasFaction()) {
 | 
			
		||||
			return;
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,8 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.Comparator;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
import com.bukkit.mcteam.factions.util.TextUtil;
 | 
			
		||||
@@ -11,25 +13,23 @@ import com.bukkit.mcteam.factions.util.TextUtil;
 | 
			
		||||
public class FCommandList extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandList() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("list");
 | 
			
		||||
		aliases.add("ls");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters.add("page");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Show a list of the factions";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// TODO put the 0 faction at the highest position
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean hasPermission(CommandSender sender) {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		ArrayList<Faction> FactionList = new ArrayList<Faction>(Faction.getAll());
 | 
			
		||||
		FactionList.remove(Faction.get(0));
 | 
			
		||||
		FactionList.remove(Faction.getNone());
 | 
			
		||||
		FactionList.remove(Faction.getSafeZone());
 | 
			
		||||
 | 
			
		||||
		int page = 1;
 | 
			
		||||
		if (parameters.size() > 0) {
 | 
			
		||||
@@ -65,7 +65,7 @@ public class FCommandList extends FBaseCommand {
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		FactionList.add(0, Faction.get(0));
 | 
			
		||||
		FactionList.add(0, Faction.getNone());
 | 
			
		||||
		
 | 
			
		||||
		int maxPage = (int)Math.floor((double)FactionList.size() / 9D);
 | 
			
		||||
		if (page < 0 || page > maxPage) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Board;
 | 
			
		||||
import com.bukkit.mcteam.factions.FLocation;
 | 
			
		||||
@@ -8,20 +8,18 @@ import com.bukkit.mcteam.factions.FLocation;
 | 
			
		||||
public class FCommandMap extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandMap() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("map");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters.add("on|off");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Show territory map, set optional auto update";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean hasPermission(CommandSender sender) {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		if (parameters.size() > 0) {
 | 
			
		||||
			String mapAutoUpdating = parameters.get(0);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
@@ -10,17 +8,10 @@ import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
public class FCommandMod extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandMod() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("mod");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("player name");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Give or revoke moderator rights";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
@@ -9,17 +7,9 @@ import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
public class FCommandOpen extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandOpen() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("open");
 | 
			
		||||
		aliases.add("close");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Switch if invitation is required to join";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,10 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Relation;
 | 
			
		||||
 | 
			
		||||
public class FCommandRelationAlly extends FRelationCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandRelationAlly() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("ally");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,10 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Relation;
 | 
			
		||||
 | 
			
		||||
public class FCommandRelationEnemy extends FRelationCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandRelationEnemy() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("enemy");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,10 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Relation;
 | 
			
		||||
 | 
			
		||||
public class FCommandRelationNeutral extends FRelationCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandRelationNeutral() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("neutral");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,30 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Board;
 | 
			
		||||
import com.bukkit.mcteam.factions.FLocation;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
import com.bukkit.mcteam.factions.Factions;
 | 
			
		||||
 | 
			
		||||
public class FCommandSafeclaim extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandSafeclaim() {
 | 
			
		||||
		aliases.add("safeclaim");
 | 
			
		||||
		aliases.add("safe");
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Claim land for the safezone";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean hasPermission(CommandSender sender) {
 | 
			
		||||
		return Factions.hasPermManageSafeZone(sender);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		FLocation flocation = new FLocation(me);
 | 
			
		||||
		Board.setFactionAt(Faction.getSafeZone(), flocation);
 | 
			
		||||
		sendMessage("This land is now a safe zone");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										38
									
								
								src/com/bukkit/mcteam/factions/commands/FCommandSethome.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/com/bukkit/mcteam/factions/commands/FCommandSethome.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
 | 
			
		||||
public class FCommandSethome extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandSethome() {
 | 
			
		||||
		aliases.add("sethome");
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Set the faction home";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		if ( ! assertHasFaction()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( ! assertMinRole(Role.MODERATOR)) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( ! Conf.homesEnabled) {
 | 
			
		||||
			me.sendMessage("Sorry, Faction homes are disabled on this server.");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// TODO may only be inside faction territory
 | 
			
		||||
		
 | 
			
		||||
		Faction myFaction = me.getFaction();
 | 
			
		||||
		myFaction.setHome(player.getLocation());
 | 
			
		||||
		
 | 
			
		||||
		myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" set the home for your faction. You can now use:");
 | 
			
		||||
		myFaction.sendMessage(new FCommandHome().getUseageTemplate(true, true));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -1,8 +1,9 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
@@ -13,21 +14,19 @@ import com.bukkit.mcteam.factions.util.TextUtil;
 | 
			
		||||
public class FCommandShow extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandShow() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("show");
 | 
			
		||||
		aliases.add("who");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters.add("faction tag");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Show faction information";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean hasPermission(CommandSender sender) {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		Faction faction;
 | 
			
		||||
		if (parameters.size() > 0) {
 | 
			
		||||
@@ -42,7 +41,7 @@ public class FCommandShow extends FBaseCommand {
 | 
			
		||||
		
 | 
			
		||||
		sendMessage(TextUtil.titleize(faction.getTag(me)));
 | 
			
		||||
		sendMessage(Conf.colorChrome+"Description: "+Conf.colorSystem+faction.getDescription());
 | 
			
		||||
		if (faction.getId() == 0) {
 | 
			
		||||
		if ( ! faction.isNormal()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
 
 | 
			
		||||
@@ -10,17 +10,10 @@ import com.bukkit.mcteam.factions.util.TextUtil;
 | 
			
		||||
public class FCommandTag extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandTag() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("tag");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("faction tag");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Change the faction tag";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
@@ -10,18 +8,12 @@ import com.bukkit.mcteam.factions.util.TextUtil;
 | 
			
		||||
public class FCommandTitle extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandTitle() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("title");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("player name");
 | 
			
		||||
		
 | 
			
		||||
		optionalParameters.add("title");
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Set or remove a players title";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -1,31 +1,35 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Board;
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FLocation;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
import com.bukkit.mcteam.factions.Factions;
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
 | 
			
		||||
public class FCommandUnclaim extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandUnclaim() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("unclaim");
 | 
			
		||||
		aliases.add("declaim");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Unclaim the land where you are standing";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		FLocation flocation = new FLocation(me);
 | 
			
		||||
		Faction otherFaction = Board.getFactionAt(flocation);
 | 
			
		||||
		
 | 
			
		||||
		if (otherFaction.isSafeZone()) {
 | 
			
		||||
			if (Factions.hasPermManageSafeZone(sender)) {
 | 
			
		||||
				Board.removeAt(flocation);
 | 
			
		||||
				sendMessage("Safe zone was unclaimed.");
 | 
			
		||||
			} else {
 | 
			
		||||
				sendMessage("This is a safe zone. You lack permissions to unclaim.");
 | 
			
		||||
			}
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( ! assertHasFaction()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
@@ -35,8 +39,7 @@ public class FCommandUnclaim extends FBaseCommand {
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		Faction myFaction = me.getFaction();
 | 
			
		||||
		FLocation flocation = new FLocation(me);
 | 
			
		||||
		Faction otherFaction = Board.getFactionAt(flocation);
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		if ( myFaction != otherFaction) {
 | 
			
		||||
			sendMessage("You don't own this land.");
 | 
			
		||||
 
 | 
			
		||||
@@ -1,25 +1,25 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Factions;
 | 
			
		||||
 | 
			
		||||
public class FCommandVersion extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FCommandVersion() {
 | 
			
		||||
		aliases = new ArrayList<String>();
 | 
			
		||||
		aliases.add("version");
 | 
			
		||||
		
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = false;
 | 
			
		||||
		
 | 
			
		||||
		helpDescription = "Which version are you using?";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean hasPermission(CommandSender sender) {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	public void perform() {
 | 
			
		||||
		sendMessage("You are running "+Factions.instance.getDescription().getFullName());
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.bukkit.mcteam.factions.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
@@ -13,13 +11,9 @@ import com.bukkit.mcteam.factions.struct.Role;
 | 
			
		||||
public class FRelationCommand extends FBaseCommand {
 | 
			
		||||
	
 | 
			
		||||
	public FRelationCommand() {
 | 
			
		||||
		requiredParameters = new ArrayList<String>();
 | 
			
		||||
		optionalParameters = new ArrayList<String>();
 | 
			
		||||
		requiredParameters.add("faction tag");
 | 
			
		||||
		helpDescription = "Set relation wish to another faction";
 | 
			
		||||
		permissions = "";
 | 
			
		||||
		
 | 
			
		||||
		senderMustBePlayer = true;
 | 
			
		||||
		helpDescription = "Set relation wish to another faction";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void relation(Relation whishedRelation, String otherFactionName) {
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@ import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FLocation;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
import com.bukkit.mcteam.factions.Factions;
 | 
			
		||||
import com.bukkit.mcteam.factions.util.TextUtil;
 | 
			
		||||
 | 
			
		||||
public class FactionsBlockListener extends BlockListener {
 | 
			
		||||
@@ -45,11 +46,20 @@ public class FactionsBlockListener extends BlockListener {
 | 
			
		||||
	public boolean playerCanBuildDestroyBlock(Player player, Block block, String action) {
 | 
			
		||||
		Faction otherFaction = Board.getFactionAt(new FLocation(block));
 | 
			
		||||
		
 | 
			
		||||
		if (otherFaction.getId() == 0) {
 | 
			
		||||
			return true; // This is no faction territory. You may build or break stuff here.
 | 
			
		||||
		if (otherFaction.isNone()) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		FPlayer me = FPlayer.get(player);
 | 
			
		||||
		
 | 
			
		||||
		if (otherFaction.isSafeZone()) {
 | 
			
		||||
			if (Factions.hasPermManageSafeZone(player)) {
 | 
			
		||||
				return true;
 | 
			
		||||
			}
 | 
			
		||||
			me.sendMessage("You can't "+action+" in a safe zone.");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		Faction myFaction = me.getFaction();
 | 
			
		||||
		
 | 
			
		||||
		// Cancel if we are not in our own territory
 | 
			
		||||
@@ -92,11 +102,12 @@ public class FactionsBlockListener extends BlockListener {
 | 
			
		||||
		Faction myFaction = me.getFaction();
 | 
			
		||||
		Faction otherFaction = Board.getFactionAt(new FLocation(block));
 | 
			
		||||
		
 | 
			
		||||
		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));
 | 
			
		||||
			//otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" tried to use "+TextUtil.getMaterialName(material)+" in your territory");
 | 
			
		||||
		if (otherFaction.isNormal() && myFaction != otherFaction) {
 | 
			
		||||
			me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction));
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// You may use doors in both safeZone and wilderness
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,18 +7,22 @@ import org.bukkit.entity.Creeper;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.Fireball;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.entity.CreatureSpawnEvent;
 | 
			
		||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
 | 
			
		||||
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
 | 
			
		||||
import org.bukkit.event.entity.EntityDamageEvent;
 | 
			
		||||
import org.bukkit.event.entity.EntityDeathEvent;
 | 
			
		||||
import org.bukkit.event.entity.EntityExplodeEvent;
 | 
			
		||||
import org.bukkit.event.entity.EntityListener;
 | 
			
		||||
import org.bukkit.event.entity.EntityTargetEvent;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Board;
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
import com.bukkit.mcteam.factions.FLocation;
 | 
			
		||||
import com.bukkit.mcteam.factions.FPlayer;
 | 
			
		||||
import com.bukkit.mcteam.factions.Faction;
 | 
			
		||||
import com.bukkit.mcteam.factions.struct.Relation;
 | 
			
		||||
import com.bukkit.mcteam.util.EntityUtil;
 | 
			
		||||
 | 
			
		||||
public class FactionsEntityListener extends EntityListener {
 | 
			
		||||
	
 | 
			
		||||
@@ -30,9 +34,9 @@ public class FactionsEntityListener extends EntityListener {
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
		Player player = (Player) entity;
 | 
			
		||||
		FPlayer follower = FPlayer.get(player);
 | 
			
		||||
		follower.onDeath();
 | 
			
		||||
		follower.sendMessage("Your power is now "+follower.getPowerRounded()+" / "+follower.getPowerMaxRounded());
 | 
			
		||||
		FPlayer fplayer = FPlayer.get(player);
 | 
			
		||||
		fplayer.onDeath();
 | 
			
		||||
		fplayer.sendMessage("Your power is now "+fplayer.getPowerRounded()+" / "+fplayer.getPowerMaxRounded());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
@@ -61,7 +65,7 @@ public class FactionsEntityListener extends EntityListener {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	// TODO what happens with the creeper or fireball then?
 | 
			
		||||
	// TODO what happens with the creeper or fireball then? Must we delete them manually?
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onEntityExplode(EntityExplodeEvent event)
 | 
			
		||||
	{
 | 
			
		||||
@@ -69,15 +73,17 @@ public class FactionsEntityListener extends EntityListener {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		Faction faction = Board.getFactionAt(new FLocation(event.getLocation()));
 | 
			
		||||
		
 | 
			
		||||
		// Explosions may happen in the wilderness
 | 
			
		||||
		if (Board.getIdAt(new FLocation(event.getLocation())) == 0) {
 | 
			
		||||
		if (faction.isNone()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (Conf.territoryBlockCreepers && event.getEntity() instanceof Creeper) {
 | 
			
		||||
		if ((Conf.territoryBlockCreepers || faction.isSafeZone()) && event.getEntity() instanceof Creeper) {
 | 
			
		||||
			// creeper which might need prevention, if inside faction territory
 | 
			
		||||
			event.setCancelled(true);
 | 
			
		||||
		} else if (Conf.territoryBlockFireballs && event.getEntity() instanceof Fireball) {
 | 
			
		||||
		} else if ((Conf.territoryBlockFireballs || faction.isSafeZone()) && event.getEntity() instanceof Fireball) {
 | 
			
		||||
			// ghast fireball which might need prevention, if inside faction territory
 | 
			
		||||
			event.setCancelled(true);
 | 
			
		||||
		}
 | 
			
		||||
@@ -87,22 +93,32 @@ public class FactionsEntityListener extends EntityListener {
 | 
			
		||||
		Entity damager = sub.getDamager();
 | 
			
		||||
		Entity damagee = sub.getEntity();
 | 
			
		||||
		int damage = sub.getDamage();
 | 
			
		||||
		if ( ! (damager instanceof Player)) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( ! (damagee instanceof Player)) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		FPlayer defender = FPlayer.get((Player)damagee);
 | 
			
		||||
		
 | 
			
		||||
		// Players can not take attack damage in a SafeZone
 | 
			
		||||
		if (Board.getFactionAt(new FLocation(defender)).isSafeZone()) {
 | 
			
		||||
			if (damager instanceof Player) {
 | 
			
		||||
				FPlayer attacker = FPlayer.get((Player)damager);
 | 
			
		||||
				attacker.sendMessage("You cant hurt other players in a SafeZone.");
 | 
			
		||||
				defender.sendMessage(attacker.getNameAndRelevant(defender)+Conf.colorSystem+" tried to hurt you.");
 | 
			
		||||
			}
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( ! (damager instanceof Player)) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		FPlayer attacker = FPlayer.get((Player)damager);
 | 
			
		||||
		Relation relation = defender.getRelation(attacker);
 | 
			
		||||
		
 | 
			
		||||
		//Log.debug(attacker.getName() + " attacked " + defender.getName());
 | 
			
		||||
		
 | 
			
		||||
		// Players without faction may be hurt anywhere
 | 
			
		||||
		if (defender.getFaction().getId() == 0) {
 | 
			
		||||
		if (defender.getFaction().isNone()) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
@@ -121,14 +137,47 @@ public class FactionsEntityListener extends EntityListener {
 | 
			
		||||
		
 | 
			
		||||
		// Damage will be dealt. However check if the damage should be reduced.
 | 
			
		||||
		if (defender.isInOwnTerritory() && Conf.territoryShieldFactor > 0) {
 | 
			
		||||
			int newDamage = (int)(damage * Conf.territoryShieldFactor);
 | 
			
		||||
			int newDamage = (int)Math.ceil(damage * (1D - Conf.territoryShieldFactor));
 | 
			
		||||
			sub.setDamage(newDamage);
 | 
			
		||||
			
 | 
			
		||||
			// Send message
 | 
			
		||||
		    String perc = MessageFormat.format("{0,number,#%}", (1.0 - Conf.territoryShieldFactor));
 | 
			
		||||
		    defender.sendMessage(Conf.colorSystem+"Enemy damage reduced by "+ChatColor.RED+perc+Conf.colorSystem+".");
 | 
			
		||||
		    String perc = MessageFormat.format("{0,number,#%}", (Conf.territoryShieldFactor)); // TODO does this display correctly??
 | 
			
		||||
		    defender.sendMessage("Enemy damage reduced by "+ChatColor.RED+perc+Conf.colorSystem+".");
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void onCreatureSpawn(CreatureSpawnEvent event) {
 | 
			
		||||
		if (event.isCancelled()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (Conf.safeZoneNerfedCreatureTypes.contains(event.getCreatureType()) && Board.getFactionAt(new FLocation(event.getLocation())).isSafeZone()) {
 | 
			
		||||
			event.setCancelled(true);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onEntityTarget(EntityTargetEvent event) {
 | 
			
		||||
		if (event.isCancelled()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// if there is a target
 | 
			
		||||
		Entity target = event.getTarget();
 | 
			
		||||
		if (target == null) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// We are interested in blocking targeting for certain mobs:
 | 
			
		||||
		if ( ! Conf.safeZoneNerfedCreatureTypes.contains(EntityUtil.creatureTypeFromEntity(event.getEntity()))) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// in case the target is in a safe zone.
 | 
			
		||||
		if (Board.getFactionAt(new FLocation(target.getLocation())).isSafeZone()) {
 | 
			
		||||
			event.setCancelled(true);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@ package com.bukkit.mcteam.factions.listeners;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.logging.Logger;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
@@ -12,6 +13,7 @@ import org.bukkit.event.player.PlayerEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerItemEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerListener;
 | 
			
		||||
import org.bukkit.event.player.PlayerMoveEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerRespawnEvent;
 | 
			
		||||
 | 
			
		||||
import com.bukkit.mcteam.factions.Board;
 | 
			
		||||
import com.bukkit.mcteam.factions.Conf;
 | 
			
		||||
@@ -99,13 +101,6 @@ public class FactionsPlayerListener extends PlayerListener{
 | 
			
		||||
		FPlayer.autoLeaveOnInactivityRoutine();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onPlayerQuit(PlayerEvent event) {
 | 
			
		||||
		// Save all players on player quit.
 | 
			
		||||
		FPlayer.save();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onPlayerMove(PlayerMoveEvent event) {
 | 
			
		||||
		FPlayer me = FPlayer.get(event.getPlayer());
 | 
			
		||||
@@ -159,7 +154,7 @@ public class FactionsPlayerListener extends PlayerListener{
 | 
			
		||||
 | 
			
		||||
		Faction otherFaction = Board.getFactionAt(new FLocation(block));
 | 
			
		||||
 | 
			
		||||
		if (otherFaction.getId() == 0) {
 | 
			
		||||
		if (otherFaction.isNone()) {
 | 
			
		||||
			return true; // This is not faction territory. Use whatever you like here.
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -174,4 +169,13 @@ public class FactionsPlayerListener extends PlayerListener{
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onPlayerRespawn(PlayerRespawnEvent event) {
 | 
			
		||||
		FPlayer me = FPlayer.get(event.getPlayer());
 | 
			
		||||
		Location home = me.getFaction().getHome();
 | 
			
		||||
		if (Conf.homesEnabled && Conf.homesTeleportToOnDeath && home != null) {
 | 
			
		||||
			event.setRespawnLocation(home);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								src/com/bukkit/mcteam/util/EntityUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/com/bukkit/mcteam/util/EntityUtil.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
package com.bukkit.mcteam.util;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Creature;
 | 
			
		||||
import org.bukkit.entity.CreatureType;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
 | 
			
		||||
public class EntityUtil {
 | 
			
		||||
	public static CreatureType creatureTypeFromEntity(Entity entity) {
 | 
			
		||||
		if ( ! (entity instanceof Creature)) {
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		String name = entity.getClass().getSimpleName();
 | 
			
		||||
		name = name.substring(5); // Remove "Craft"
 | 
			
		||||
		
 | 
			
		||||
		return CreatureType.fromName(name);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user