mirror of
https://github.com/taoneill/war.git
synced 2025-01-08 08:47:58 +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.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import bukkit.tommytony.war.command.AbstractWarCommand;
|
||||||
|
import bukkit.tommytony.war.command.WarzonesCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Tim Düsterhus
|
* @author Tim Düsterhus
|
||||||
* @package bukkit.tommytony.war
|
* @package bukkit.tommytony.war
|
||||||
@ -27,10 +30,11 @@ public class WarCommandHandler {
|
|||||||
arguments = args;
|
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) {
|
return commandObj.handle();
|
||||||
sender.sendMessage(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,22 @@ package bukkit.tommytony.war.command;
|
|||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import bukkit.tommytony.war.WarCommandHandler;
|
||||||
|
|
||||||
public abstract class AbstractWarCommand {
|
public abstract class AbstractWarCommand {
|
||||||
|
|
||||||
protected CommandSender sender;
|
protected CommandSender sender;
|
||||||
protected String[] args;
|
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.sender = sender;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public boolean handle();
|
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 org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import bukkit.tommytony.war.WarCommandHandler;
|
||||||
|
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
|
|
||||||
public abstract class AbstractWarzoneCommand extends AbstractWarCommand {
|
public abstract class AbstractWarzoneCommand extends AbstractWarCommand {
|
||||||
protected int parameterCount = 0;
|
protected int parameterCount = 0;
|
||||||
protected Warzone zone = null;
|
protected Warzone zone = null;
|
||||||
public AbstractWarzoneCommand(CommandSender sender, String[] args) {
|
public AbstractWarzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||||
super(sender, args);
|
super(handler, sender, args);
|
||||||
|
|
||||||
// TODO: Find the warzone either from name (support console too) or from location
|
// 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