From 38bcafae01e7ab91dbc84891c3d6346d82f54e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 17 Jul 2011 20:00:27 +0200 Subject: [PATCH] Removed AbstractWarzoneCommand and moved methods into War --- .../main/java/bukkit/tommytony/war/War.java | 23 +++++++++++ .../war/command/AbstractWarzoneCommand.java | 40 ------------------- .../tommytony/war/command/JoinCommand.java | 4 +- .../tommytony/war/command/LeaveCommand.java | 2 +- .../tommytony/war/command/TeamCommand.java | 2 +- .../tommytony/war/command/TeamsCommand.java | 7 ++-- 6 files changed, 31 insertions(+), 47 deletions(-) delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/AbstractWarzoneCommand.java diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index b9de49b..6a40b09 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -228,6 +228,29 @@ public class War extends JavaPlugin { return true;*/ } + public Warzone getWarzoneFromLocation(Player player) { + return this.getWarzoneFromLocation(player.getLocation()); + } + + public Warzone getWarzoneFromLocation(Location location) { + Warzone zone = War.war.warzone(location); + if (zone == null) { + ZoneLobby lobby = War.war.lobby(location); + if (lobby == null) return null; + zone = lobby.getZone(); + } + return zone; + } + + public Warzone getWarzoneFromName(String name) { + for (Warzone zone : War.war.getWarzones()) { + if (zone.getName().toLowerCase().equals(name.toLowerCase())) { + return zone; + } + } + return null; + } + /** * Converts the player-inventory to a loadout hashmap * diff --git a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarzoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/AbstractWarzoneCommand.java deleted file mode 100644 index 494ad4f..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarzoneCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; - -public abstract class AbstractWarzoneCommand extends AbstractWarCommand { - public AbstractWarzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) { - super(handler, sender, args); - } - - public Warzone getWarzoneFromLocation(Player player) { - return this.getWarzoneFromLocation(player.getLocation()); - } - - public Warzone getWarzoneFromLocation(Location location) { - Warzone zone = War.war.warzone(location); - if (zone == null) { - ZoneLobby lobby = War.war.lobby(location); - if (lobby == null) return null; - zone = lobby.getZone(); - } - return zone; - } - - public Warzone getWarzoneFromName(String name) { - for (Warzone zone : War.war.getWarzones()) { - if (zone.getName().toLowerCase().equals(name.toLowerCase())) { - return zone; - } - } - return null; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java b/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java index 891ade3..93817f6 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java @@ -13,7 +13,7 @@ import com.tommytony.war.TeamKind; import com.tommytony.war.TeamKinds; import com.tommytony.war.Warzone; -public class JoinCommand extends AbstractWarzoneCommand { +public class JoinCommand extends AbstractWarCommand { public JoinCommand(WarCommandHandler handler, CommandSender sender, String[] args) { super(handler, sender, args); } @@ -29,7 +29,7 @@ public class JoinCommand extends AbstractWarzoneCommand { if (this.args.length < 1) { return false; } - Warzone zone = this.getWarzoneFromLocation(player); + Warzone zone = War.war.getWarzoneFromLocation(player); if (zone == null) { War.war.badMsg(player, "No such warzone."); return true; diff --git a/war/src/main/java/bukkit/tommytony/war/command/LeaveCommand.java b/war/src/main/java/bukkit/tommytony/war/command/LeaveCommand.java index 6c03a03..0b6db93 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/LeaveCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/LeaveCommand.java @@ -8,7 +8,7 @@ import bukkit.tommytony.war.WarCommandHandler; import com.tommytony.war.Warzone; -public class LeaveCommand extends AbstractWarzoneCommand { +public class LeaveCommand extends AbstractWarCommand { public LeaveCommand(WarCommandHandler handler, CommandSender sender, String[] args) { super(handler, sender, args); } diff --git a/war/src/main/java/bukkit/tommytony/war/command/TeamCommand.java b/war/src/main/java/bukkit/tommytony/war/command/TeamCommand.java index 9e08e9c..48ee5b2 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/TeamCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/TeamCommand.java @@ -9,7 +9,7 @@ import bukkit.tommytony.war.WarCommandHandler; import com.tommytony.war.Team; -public class TeamCommand extends AbstractWarzoneCommand { +public class TeamCommand extends AbstractWarCommand { public TeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) { super(handler, sender, args); } diff --git a/war/src/main/java/bukkit/tommytony/war/command/TeamsCommand.java b/war/src/main/java/bukkit/tommytony/war/command/TeamsCommand.java index 99dc15e..618b691 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/TeamsCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/TeamsCommand.java @@ -3,11 +3,12 @@ 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.Warzone; -public class TeamsCommand extends AbstractWarzoneCommand { +public class TeamsCommand extends AbstractWarCommand { public TeamsCommand(WarCommandHandler handler, CommandSender sender, String[] args) { super(handler, sender, args); } @@ -15,12 +16,12 @@ public class TeamsCommand extends AbstractWarzoneCommand { public boolean handle() { Warzone zone; if (this.args.length == 1) { - zone = this.getWarzoneFromName(this.args[0]); + zone = War.war.getWarzoneFromName(this.args[0]); } else { if (!(this.sender instanceof Player)) { return false; } - zone = this.getWarzoneFromLocation((Player) this.sender); + zone = War.war.getWarzoneFromLocation((Player) this.sender); } if (zone == null) { return true;