Added Warzone-Command

This commit is contained in:
Tim Düsterhus 2011-07-17 18:11:14 +02:00
parent a1f1b65d6e
commit 1bf770d340
3 changed files with 53 additions and 19 deletions

View File

@ -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 <zone-name> to " + "teleport to a warzone. ");
}
private boolean updateZoneFromNamedParams(Warzone warzone, Player player, String[] arguments) {
try {
Map<String, String> namedParams = new HashMap<String, String>();

View File

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

View File

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