diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index ae53001..9bdcc67 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -44,6 +44,7 @@ public class War extends JavaPlugin { private WarPlayerListener playerListener = new WarPlayerListener(); private WarEntityListener entityListener = new WarEntityListener(); private WarBlockListener blockListener = new WarBlockListener(); + private WarCommandHandler commandHandler = new WarCommandHandler(); private Logger log; private PluginDescriptionFile desc = null; private boolean loaded = false; @@ -173,6 +174,8 @@ public class War extends JavaPlugin { * Handles war commands */ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + return this.commandHandler.handle(sender, cmd, commandLabel, args); + if (sender instanceof Player) { Player player = (Player) sender; String command = cmd.getName(); @@ -954,23 +957,6 @@ public class War extends JavaPlugin { } } - private void performZones(Player player) { - String warzonesMessage = "Warzones: "; - if (this.getWarzones().isEmpty()) { - warzonesMessage += "none."; - } - for (Warzone warzone : this.getWarzones()) { - - warzonesMessage += warzone.getName() + " (" + warzone.getTeams().size() + " teams, "; - int playerTotal = 0; - for (Team team : warzone.getTeams()) { - playerTotal += team.getPlayers().size(); - } - warzonesMessage += playerTotal + " players) "; - } - this.msg(player, warzonesMessage + " Use /zone to " + "teleport to a warzone. "); - } - 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 8dcd23b..11a294e 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java +++ b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java @@ -3,8 +3,7 @@ package bukkit.tommytony.war; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import bukkit.tommytony.war.command.AbstractWarCommand; -import bukkit.tommytony.war.command.WarzonesCommand; +import bukkit.tommytony.war.command.*; /** * @author Tim Düsterhus @@ -34,6 +33,13 @@ public class WarCommandHandler { if (command.equals("zones") || command.equals("warzones")) { commandObj = new WarzonesCommand(this, sender, arguments); } + else if (command.equals("zone") || command.equals("warzone")) { + commandObj = new WarzoneCommand(this, sender, arguments); + } + else { + // we are not responsible for this command + return true; + } return commandObj.handle(); } diff --git a/war/src/main/java/bukkit/tommytony/war/command/WarzoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/WarzoneCommand.java new file mode 100644 index 0000000..4339c7a --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/WarzoneCommand.java @@ -0,0 +1,42 @@ +package bukkit.tommytony.war.command; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import bukkit.tommytony.war.War; +import bukkit.tommytony.war.WarCommandHandler; + +import com.tommytony.war.Team; +import com.tommytony.war.Warzone; + +public class WarzoneCommand extends AbstractWarCommand { + public WarzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) { + super(handler, sender, args); + } + + public boolean handle() { + if (!(this.sender instanceof Player)) return true; + + Player player = (Player) this.sender; + if (this.args.length < 1) { + return false; + } else if (!War.war.canWarp(player)) { + War.war.badMsg(player, "Can't warp to zone. You need the 'war.warp' permission."); + } else { + for (Warzone warzone : War.war.getWarzones()) { + if (warzone.getName().toLowerCase().startsWith(this.args[0].toLowerCase()) && warzone.getTeleport() != null) { + Team playerTeam = War.war.getPlayerTeam(player.getName()); + if (playerTeam != null) { + Warzone playerWarzone = War.war.getPlayerTeamWarzone(player.getName()); + playerWarzone.handlePlayerLeave(player, warzone.getTeleport(), true); + } else { + player.teleport(warzone.getTeleport()); + } + return true; + } + } + War.war.badMsg(player, "No such warzone."); + } + return true; + } +}