From b0f09db0542bb710d5f63fa0e034c7aef9c97d2c Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 23 Mar 2011 17:39:56 +0100 Subject: [PATCH] Safe zones and faction homes :D :D --- plugin.yml | 2 +- src/com/bukkit/mcteam/factions/Board.java | 4 +- src/com/bukkit/mcteam/factions/Conf.java | 26 +++-- src/com/bukkit/mcteam/factions/FPlayer.java | 11 ++- src/com/bukkit/mcteam/factions/Faction.java | 49 +++++++++- src/com/bukkit/mcteam/factions/Factions.java | 77 +++++++++++---- .../factions/MyLocationTypeAdapter.java | 51 ++++++++++ .../factions/commands/FBaseCommand.java | 58 +++++------ .../factions/commands/FCommandAdmin.java | 9 -- .../factions/commands/FCommandChat.java | 10 -- .../factions/commands/FCommandClaim.java | 29 +++--- .../factions/commands/FCommandCreate.java | 20 ++-- .../factions/commands/FCommandDeinvite.java | 9 -- .../commands/FCommandDescription.java | 9 -- .../factions/commands/FCommandHelp.java | 96 ++++++++++--------- .../factions/commands/FCommandHome.java | 36 +++++++ .../factions/commands/FCommandInvite.java | 9 -- .../factions/commands/FCommandJoin.java | 14 +-- .../factions/commands/FCommandKick.java | 9 -- .../factions/commands/FCommandLeave.java | 15 ++- .../factions/commands/FCommandList.java | 20 ++-- .../mcteam/factions/commands/FCommandMap.java | 14 ++- .../mcteam/factions/commands/FCommandMod.java | 9 -- .../factions/commands/FCommandOpen.java | 10 -- .../commands/FCommandRelationAlly.java | 3 - .../commands/FCommandRelationEnemy.java | 3 - .../commands/FCommandRelationNeutral.java | 3 - .../factions/commands/FCommandSafeclaim.java | 30 ++++++ .../factions/commands/FCommandSethome.java | 38 ++++++++ .../factions/commands/FCommandShow.java | 17 ++-- .../mcteam/factions/commands/FCommandTag.java | 7 -- .../factions/commands/FCommandTitle.java | 10 +- .../factions/commands/FCommandUnclaim.java | 27 +++--- .../factions/commands/FCommandVersion.java | 14 +-- .../factions/commands/FRelationCommand.java | 8 +- .../listeners/FactionsBlockListener.java | 21 +++- .../listeners/FactionsEntityListener.java | 81 ++++++++++++---- .../listeners/FactionsPlayerListener.java | 20 ++-- src/com/bukkit/mcteam/util/EntityUtil.java | 18 ++++ 39 files changed, 562 insertions(+), 334 deletions(-) create mode 100644 src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandHome.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandSafeclaim.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandSethome.java create mode 100644 src/com/bukkit/mcteam/util/EntityUtil.java diff --git a/plugin.yml b/plugin.yml index 7f628b2c..716f3102 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: Factions -version: 1.1 +version: 1.1 alpha main: com.bukkit.mcteam.factions.Factions commands: f: diff --git a/src/com/bukkit/mcteam/factions/Board.java b/src/com/bukkit/mcteam/factions/Board.java index 12deffd8..222976d1 100644 --- a/src/com/bukkit/mcteam/factions/Board.java +++ b/src/com/bukkit/mcteam/factions/Board.java @@ -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()+"+"; } diff --git a/src/com/bukkit/mcteam/factions/Conf.java b/src/com/bukkit/mcteam/factions/Conf.java index d67f479d..00e9b747 100644 --- a/src/com/bukkit/mcteam/factions/Conf.java +++ b/src/com/bukkit/mcteam/factions/Conf.java @@ -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 territoryProtectedMaterials = new HashSet(); public static Set territoryDenyUseageMaterials = new HashSet(); - public static transient Set instaDestroyMaterials = new HashSet(); // This one is not really configuration therefore transient - - public static boolean allowNoSlashCommand = true; - public static double autoLeaveFactionAfterDaysOfInactivity = 14; + public static transient Set safeZoneNerfedCreatureTypes = new HashSet(); + + public static transient Set instaDestroyMaterials = new HashSet(); // This one is not really configuration therefore transient + 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); } // -------------------------------------------- // diff --git a/src/com/bukkit/mcteam/factions/FPlayer.java b/src/com/bukkit/mcteam/factions/FPlayer.java index 1b1743ce..6cf53b24 100644 --- a/src/com/bukkit/mcteam/factions/FPlayer.java +++ b/src/com/bukkit/mcteam/factions/FPlayer.java @@ -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(); } diff --git a/src/com/bukkit/mcteam/factions/Faction.java b/src/com/bukkit/mcteam/factions/Faction.java index 7520c44f..043d8e90 100644 --- a/src/com/bukkit/mcteam/factions/Faction.java +++ b/src/com/bukkit/mcteam/factions/Faction.java @@ -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); } diff --git a/src/com/bukkit/mcteam/factions/Factions.java b/src/com/bukkit/mcteam/factions/Factions.java index ee1e5d10..79e240a4 100644 --- a/src/com/bukkit/mcteam/factions/Factions.java +++ b/src/com/bukkit/mcteam/factions/Factions.java @@ -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,6 +166,21 @@ public class Factions extends JavaPlugin { // Integration with other plugins // -------------------------------------------- // + private void setupHelp() { + if (helpPlugin != null) { + return; + } + + Plugin test = this.getServer().getPluginManager().getPlugin("Help"); + + if (test != null) { + helpPlugin = ((Help) test); + Factions.log("Found and will use plugin "+helpPlugin.getDescription().getFullName()); + helpPlugin.registerCommand(this.getBaseCommand()+" help *[page]", "Factions plugin help.", this, false); + helpPlugin.registerCommand("help factions", "instead use: /f help", helpPlugin, true); + } + } + private void setupPermissions() { if (Permissions != null) { return; @@ -171,21 +196,38 @@ public class Factions extends JavaPlugin { } } - private void setupHelp() { - if (helpPlugin != null) { - return; - } - - Plugin test = this.getServer().getPluginManager().getPlugin("Help"); - - if (test != null) { - helpPlugin = ((Help) test); - Factions.log("Found and will use plugin "+helpPlugin.getDescription().getFullName()); - helpPlugin.registerCommand(this.getBaseCommand()+" help *[page]", "Factions plugin help.", this, false); - helpPlugin.registerCommand("help factions", "instead use: /f help", helpPlugin, true); - } + // -------------------------------------------- // + // 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(); } } diff --git a/src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java b/src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java new file mode 100644 index 00000000..39813778 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java @@ -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, JsonSerializer { + 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; + } +} diff --git a/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java b/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java index 0b202fb2..4fa6de0a 100644 --- a/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java +++ b/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java @@ -15,12 +15,9 @@ import com.bukkit.mcteam.factions.util.TextUtil; public class FBaseCommand { public List aliases; - public List requiredParameters; public List optionalParameters; - public String permissions; - public String helpNameAndParams; public String helpDescription; @@ -33,12 +30,11 @@ public class FBaseCommand { public FBaseCommand() { + aliases = new ArrayList(); requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); - permissions = ""; - - senderMustBePlayer = false; + senderMustBePlayer = true; helpNameAndParams = "fail!"; helpDescription = "no description"; @@ -47,12 +43,7 @@ public class FBaseCommand { public List getAliases() { return aliases; } - - public String getBaseName() { - // TODO fetch from the plugin.yaml or something... - return "f"; - } - + public void execute(CommandSender sender, List 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 parts = new ArrayList(); @@ -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 // -------------------------------------------- // diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java b/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java index b2a39628..f993a780 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java @@ -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(); aliases.add("admin"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); requiredParameters.add("player name"); - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Hand over your admin rights"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandChat.java b/src/com/bukkit/mcteam/factions/commands/FCommandChat.java index 42c66b5e..97f670f2 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandChat.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandChat.java @@ -1,21 +1,11 @@ package com.bukkit.mcteam.factions.commands; -import java.util.ArrayList; - public class FCommandChat extends FBaseCommand { public FCommandChat() { - aliases = new ArrayList(); aliases.add("chat"); aliases.add("c"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); - - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Switch faction only chat on and off"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java b/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java index d2ac1630..e8bf788a 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java @@ -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(); aliases.add("claim"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); - - 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"); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java b/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java index 0e642f28..982dc17a 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java @@ -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(); aliases.add("create"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); 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)); } } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java b/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java index c0f360f2..96fff0b6 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java @@ -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(); aliases.add("deinvite"); aliases.add("deinv"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); requiredParameters.add("player name"); - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Remove a pending invitation"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java b/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java index 556b9f40..fde94041 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java @@ -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(); aliases.add("desc"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); requiredParameters.add("desc"); - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Change the faction description"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java b/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java index ddcbcf48..d325e85c 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java @@ -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(); aliases.add("help"); aliases.add("h"); aliases.add("?"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); - optionalParameters.add("page"); - - permissions = ""; - - senderMustBePlayer = false; + optionalParameters.add("page"); 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(); + pageLines = new ArrayList(); + 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(); + 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(); + pageLines = new ArrayList(); 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(); - 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(); + 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(); - 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."); - + pageLines = new ArrayList(); + 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("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(); + pageLines = new ArrayList(); + 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); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandHome.java b/src/com/bukkit/mcteam/factions/commands/FCommandHome.java new file mode 100644 index 00000000..3d1268f4 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandHome.java @@ -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()); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java b/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java index 85383faa..a5b0b569 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java @@ -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(); aliases.add("invite"); aliases.add("inv"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); requiredParameters.add("player name"); - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Invite a player"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java b/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java index 6d31a29b..46742ac6 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java @@ -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(); aliases.add("join"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); 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; diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandKick.java b/src/com/bukkit/mcteam/factions/commands/FCommandKick.java index 81ea1fcd..2271f4b0 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandKick.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandKick.java @@ -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(); aliases.add("kick"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); requiredParameters.add("player name"); - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Kick a player from the faction"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java b/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java index 213f97c1..27cb4f59 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java @@ -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(); aliases.add("leave"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); - - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Leave your faction"; } + @Override + public boolean hasPermission(CommandSender sender) { + return true; + } + public void perform() { if ( ! assertHasFaction()) { return; diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandList.java b/src/com/bukkit/mcteam/factions/commands/FCommandList.java index a5044af9..1864addc 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandList.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandList.java @@ -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(); aliases.add("list"); aliases.add("ls"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); 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 FactionList = new ArrayList(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) { diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandMap.java b/src/com/bukkit/mcteam/factions/commands/FCommandMap.java index 71bc048d..9699ae41 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandMap.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandMap.java @@ -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(); aliases.add("map"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); 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); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandMod.java b/src/com/bukkit/mcteam/factions/commands/FCommandMod.java index 07c40869..720a6862 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandMod.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandMod.java @@ -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(); aliases.add("mod"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); requiredParameters.add("player name"); - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Give or revoke moderator rights"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java b/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java index 3e05eaa7..b0ddc2b5 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java @@ -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(); aliases.add("open"); aliases.add("close"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); - - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Switch if invitation is required to join"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java b/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java index 514ed393..8e826f7c 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java @@ -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(); aliases.add("ally"); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java b/src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java index 8e173f53..c4ca999e 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java @@ -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(); aliases.add("enemy"); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java b/src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java index 4f5f982e..4107181f 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java @@ -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(); aliases.add("neutral"); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandSafeclaim.java b/src/com/bukkit/mcteam/factions/commands/FCommandSafeclaim.java new file mode 100644 index 00000000..101a06fe --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandSafeclaim.java @@ -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"); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandSethome.java b/src/com/bukkit/mcteam/factions/commands/FCommandSethome.java new file mode 100644 index 00000000..f47c3a1b --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandSethome.java @@ -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)); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandShow.java b/src/com/bukkit/mcteam/factions/commands/FCommandShow.java index 5fb7fd0f..8506006b 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandShow.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandShow.java @@ -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(); aliases.add("show"); aliases.add("who"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); 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; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandTag.java b/src/com/bukkit/mcteam/factions/commands/FCommandTag.java index 3af48ba6..bc9e3035 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandTag.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandTag.java @@ -10,17 +10,10 @@ import com.bukkit.mcteam.factions.util.TextUtil; public class FCommandTag extends FBaseCommand { public FCommandTag() { - aliases = new ArrayList(); aliases.add("tag"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); requiredParameters.add("faction tag"); - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Change the faction tag"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java b/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java index 8e701b0b..b87a445c 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java @@ -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(); aliases.add("title"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); requiredParameters.add("player name"); + optionalParameters.add("title"); - permissions = ""; - - senderMustBePlayer = true; - helpDescription = "Set or remove a players title"; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java b/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java index 2ea08b95..649f2b0e 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java @@ -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(); aliases.add("unclaim"); aliases.add("declaim"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); - - 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."); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java b/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java index 6f54b751..80c198b9 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java @@ -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(); aliases.add("version"); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); - - 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()); } diff --git a/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java b/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java index 4884997b..3cc4412a 100644 --- a/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java +++ b/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java @@ -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(); - optionalParameters = new ArrayList(); 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) { diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java index 9d22207f..72f0e97e 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java @@ -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; } } diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java index adee1031..ab67a252 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java @@ -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); + } + } } diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java index 3c8eff5a..c746e27a 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java @@ -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); + } + } } diff --git a/src/com/bukkit/mcteam/util/EntityUtil.java b/src/com/bukkit/mcteam/util/EntityUtil.java new file mode 100644 index 00000000..7f05fa33 --- /dev/null +++ b/src/com/bukkit/mcteam/util/EntityUtil.java @@ -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); + } +}