diff --git a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java index 3c427a2..8dcd23b 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java +++ b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java @@ -3,6 +3,9 @@ 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; + /** * @author Tim Düsterhus * @package bukkit.tommytony.war @@ -27,10 +30,11 @@ public class WarCommandHandler { arguments = args; } - return true; - } + AbstractWarCommand commandObj = null; + if (command.equals("zones") || command.equals("warzones")) { + commandObj = new WarzonesCommand(this, sender, arguments); + } - public void msg(CommandSender sender, String message) { - sender.sendMessage(message); + return commandObj.handle(); } } diff --git a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarCommand.java b/war/src/main/java/bukkit/tommytony/war/command/AbstractWarCommand.java index f5e2d06..214a710 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/AbstractWarCommand.java @@ -2,14 +2,22 @@ package bukkit.tommytony.war.command; import org.bukkit.command.CommandSender; +import bukkit.tommytony.war.WarCommandHandler; + public abstract class AbstractWarCommand { protected CommandSender sender; protected String[] args; - public AbstractWarCommand(CommandSender sender, String[] args) { + protected WarCommandHandler handler; + public AbstractWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) { + this.handler = handler; this.sender = sender; this.args = args; } abstract public boolean handle(); + + public void msg(String message) { + this.sender.sendMessage(message); + } } diff --git a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarzoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/AbstractWarzoneCommand.java index 7d87924..a4036a2 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarzoneCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/AbstractWarzoneCommand.java @@ -2,13 +2,15 @@ package bukkit.tommytony.war.command; import org.bukkit.command.CommandSender; +import bukkit.tommytony.war.WarCommandHandler; + import com.tommytony.war.Warzone; public abstract class AbstractWarzoneCommand extends AbstractWarCommand { protected int parameterCount = 0; protected Warzone zone = null; - public AbstractWarzoneCommand(CommandSender sender, String[] args) { - super(sender, args); + public AbstractWarzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) { + super(handler, sender, args); // TODO: Find the warzone either from name (support console too) or from location } diff --git a/war/src/main/java/bukkit/tommytony/war/command/WarzonesCommand.java b/war/src/main/java/bukkit/tommytony/war/command/WarzonesCommand.java new file mode 100644 index 0000000..114e0d3 --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/WarzonesCommand.java @@ -0,0 +1,34 @@ +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 WarzonesCommand extends AbstractWarCommand { + public WarzonesCommand(WarCommandHandler handler, CommandSender sender, String[] args) { + super(handler, sender, args); + } + + public boolean handle() { + String warzonesMessage = "Warzones: "; + if (War.war.getWarzones().isEmpty()) { + warzonesMessage += "none."; + } + for (Warzone warzone : War.war.getWarzones()) { + + warzonesMessage += warzone.getName() + " (" + warzone.getTeams().size() + " teams, "; + int playerTotal = 0; + for (Team team : warzone.getTeams()) { + playerTotal += team.getPlayers().size(); + } + warzonesMessage += playerTotal + " players)"; + } + this.sender.sendMessage(warzonesMessage + ((this.sender instanceof Player) ? " Use /zone to teleport to a warzone." : "")); + return true; + } +}