mirror of
https://github.com/taoneill/war.git
synced 2025-02-02 12:41:22 +01:00
Half implementation of /teams
This commit is contained in:
parent
1bf770d340
commit
554335b6bd
@ -177,32 +177,7 @@ public class War extends JavaPlugin {
|
||||
return this.commandHandler.handle(sender, cmd, commandLabel, args);
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
String command = cmd.getName();
|
||||
String[] arguments = null;
|
||||
// Handle both /war <command> and /<war command>. I.e. "/war zone temple" == "/zone temple"
|
||||
String helpMessage = "War is on. Please pick your battle. " + "Try /warhub, /zones and /zone. Further instructions at war.tommytony.com/instructions.";
|
||||
if ((command.equals("war") || command.equals("War")) && args.length > 0) {
|
||||
command = args[0];
|
||||
arguments = new String[args.length - 1];
|
||||
for (int i = 1; i <= arguments.length; i++) {
|
||||
arguments[i - 1] = args[i];
|
||||
}
|
||||
if (arguments.length == 1 && (arguments[0].equals("help") || arguments[0].equals("h"))) {
|
||||
this.msg(player, helpMessage);
|
||||
}
|
||||
} else if (command.equals("war") || command.equals("War")) {
|
||||
this.msg(player, helpMessage);
|
||||
} else {
|
||||
arguments = args;
|
||||
}
|
||||
|
||||
// Player commands: /warzones, /warzone, /teams, /join, /leave
|
||||
if (command.equals("zones") || command.equals("warzones")) {
|
||||
this.performZones(player);
|
||||
} else if (command.equals("zone") || command.equals("warzone")) {
|
||||
this.performZone(player, arguments);
|
||||
} else if (command.equals("teams")) {
|
||||
if (command.equals("teams")) {
|
||||
this.performTeams(player);
|
||||
} else if (command.equals("join") && this.canPlayWar(player)) {
|
||||
this.performJoin(player, arguments);
|
||||
@ -931,32 +906,6 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void performZone(Player player, String[] arguments) {
|
||||
if (arguments.length < 1) {
|
||||
this.badMsg(player, "Usage: /zone <warzone-name>.");
|
||||
} else if (!this.canWarp(player)) {
|
||||
this.badMsg(player, "Can't warp to zone. You need the 'war.warp' permission.");
|
||||
} else {
|
||||
boolean warped = false;
|
||||
for (Warzone warzone : this.getWarzones()) {
|
||||
if (warzone.getName().toLowerCase().startsWith(arguments[0].toLowerCase()) && warzone.getTeleport() != null) {
|
||||
Team playerTeam = this.getPlayerTeam(player.getName());
|
||||
if (playerTeam != null) {
|
||||
Warzone playerWarzone = this.getPlayerTeamWarzone(player.getName());
|
||||
playerWarzone.handlePlayerLeave(player, warzone.getTeleport(), true);
|
||||
} else {
|
||||
player.teleport(warzone.getTeleport());
|
||||
}
|
||||
warped = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!warped) {
|
||||
this.badMsg(player, "No such warzone.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateZoneFromNamedParams(Warzone warzone, Player player, String[] arguments) {
|
||||
try {
|
||||
Map<String, String> namedParams = new HashMap<String, String>();
|
||||
|
@ -1,19 +1,41 @@
|
||||
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 {
|
||||
protected int parameterCount = 0;
|
||||
protected Warzone zone = null;
|
||||
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
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class TeamsCommand extends AbstractWarzoneCommand {
|
||||
public TeamsCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = this.getWarzoneFromName(this.args[0]);
|
||||
} else {
|
||||
if (!(this.sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = this.getWarzoneFromLocation((Player) this.sender);
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
// zone.getTeams();
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user