From a0c8e1eb7ee8dab43a15095f7e7243a54e7c8d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 28 Jul 2011 13:27:44 +0200 Subject: [PATCH] Adding SetZoneCommand --- .../main/java/bukkit/tommytony/war/War.java | 28 +--------- .../tommytony/war/WarCommandHandler.java | 3 ++ .../tommytony/war/command/SetZoneCommand.java | 52 +++++++++++++++++++ 3 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetZoneCommand.java diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index a93040b..398e701 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -178,9 +178,7 @@ public class War extends JavaPlugin { /* if (this.isZoneMaker(player)) { // Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone - if (command.equals("setzone")) { - this.performSetZone(player, arguments); - } else if (command.equals("setzonelobby")) { + if (command.equals("setzonelobby")) { this.performSetZoneLobby(player, arguments); } else if (command.equals("savezone")) { this.performSaveZone(player, arguments); @@ -448,30 +446,6 @@ public class War extends JavaPlugin { } } - public void performSetZone(Player player, String[] arguments) { - if (arguments.length < 2 || arguments.length > 2 || (arguments.length == 2 && (!arguments[1].equals("southeast") && !arguments[1].equals("northwest") && !arguments[1].equals("se") && !arguments[1].equals("nw") && !arguments[1].equals("corner1") && !arguments[1].equals("corner2") && !arguments[1].equals("c1") && !arguments[1].equals("c2") && !arguments[1].equals("pos1") && !arguments[1].equals("pos2") && !arguments[1].equals("wand")))) { - if (arguments.length == 1) { - // we only have a zone name, default to wand mode - this.addWandBearer(player, arguments[0]); - } else { - this.badMsg(player, "Usage: == /setzone <'northwest'/'southeast'/'nw'/'se'> (NW defaults to top block, SE to bottom). " + "== /setzone wand (gives you a wooden sword to right and left click, drop to disable). " + "== /setzone <'corner1'/'corner2'/'c1'/'c2'/'pos1'/'pos2'> (block where you're standing). " + "Set one corner, then the next. Defines the outline of the warzone, which will be reset at the start of every battle. " + "Saves the zone blocks if the outline is valid."); - } - } else { - ZoneSetter setter = new ZoneSetter(player, arguments[0]); - if (arguments[1].equals("northwest") || arguments[1].equals("nw")) { - setter.placeNorthwest(); - } else if (arguments[1].equals("southeast") || arguments[1].equals("se")) { - setter.placeSoutheast(); - } else if (arguments[1].equals("corner1") || arguments[1].equals("c1") || arguments[1].equals("pos1")) { - setter.placeCorner1(); - } else if (arguments[1].equals("corner2") || arguments[1].equals("c2") || arguments[1].equals("pos2")) { - setter.placeCorner2(); - } else if (arguments[1].equals("wand")) { - this.addWandBearer(player, arguments[0]); - } - } - } - private boolean updateZoneFromNamedParams(Warzone warzone, Player player, String[] arguments) { try { Map namedParams = new HashMap(); diff --git a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java index 65543f2..6d2d3de 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java +++ b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java @@ -52,6 +52,9 @@ public class WarCommandHandler { else if (command.equals("team")) { commandObj = new TeamCommand(this, sender, arguments); } + else if (command.equals("setzone")) { + commandObj = new SetZoneCommand(this, sender, arguments); + } else if (command.equals("deletezone")) { commandObj = new DeleteZoneCommand(this, sender, arguments); } diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetZoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetZoneCommand.java new file mode 100644 index 0000000..94bd814 --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/SetZoneCommand.java @@ -0,0 +1,52 @@ +package bukkit.tommytony.war.command; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.tommytony.war.ZoneSetter; + +import bukkit.tommytony.war.War; +import bukkit.tommytony.war.WarCommandHandler; + +public class SetZoneCommand extends AbstractZoneMakerCommand { + + public SetZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NoZoneMakerException { + super(handler, sender, args); + } + + @Override + public boolean handle() { + if (!(this.sender instanceof Player)) { + return false; + } + + Player player = (Player) this.sender; + + if (this.args.length == 0) { + return false; + } else if (this.args.length > 2) { + return false; + } else if (this.args.length == 1) { + War.war.addWandBearer(player, this.args[0]); + } else if (this.args.length == 2) { + if (!this.args[1].equals("southeast") && !this.args[1].equals("northwest") && !this.args[1].equals("se") && !this.args[1].equals("nw") && !this.args[1].equals("corner1") && !this.args[1].equals("corner2") && !this.args[1].equals("c1") && !this.args[1].equals("c2") && !this.args[1].equals("pos1") && !this.args[1].equals("pos2") && !this.args[1].equals("wand")) { + return false; + } + + ZoneSetter setter = new ZoneSetter(player, this.args[0]); + if (this.args[1].equals("northwest") || this.args[1].equals("nw")) { + setter.placeNorthwest(); + } else if (this.args[1].equals("southeast") || this.args[1].equals("se")) { + setter.placeSoutheast(); + } else if (this.args[1].equals("corner1") || this.args[1].equals("c1") || this.args[1].equals("pos1")) { + setter.placeCorner1(); + } else if (this.args[1].equals("corner2") || this.args[1].equals("c2") || this.args[1].equals("pos2")) { + setter.placeCorner2(); + } else if (this.args[1].equals("wand")) { + War.war.addWandBearer(player, this.args[0]); + } + } + + return true; + } +}