mirror of
https://github.com/taoneill/war.git
synced 2025-01-05 23:37:37 +01:00
First implemented command
This commit is contained in:
parent
5565024a7c
commit
a1f1b65d6e
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 <zone-name> to teleport to a warzone." : ""));
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user