Removed AbstractWarzoneCommand and moved methods into War

This commit is contained in:
Tim Düsterhus 2011-07-17 20:00:27 +02:00
parent 92bd84da75
commit 38bcafae01
6 changed files with 31 additions and 47 deletions

View File

@ -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
*

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;