mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 12:46:11 +01:00
Validate argument-count
This commit is contained in:
parent
bc77ce5892
commit
15c3fadbb3
@ -186,14 +186,6 @@ public class War extends JavaPlugin {
|
||||
this.performSaveZone(player, arguments);
|
||||
} else if (command.equals("setzoneconfig") || command.equals("zonecfg")) {
|
||||
this.performSetZoneConfig(player, arguments);
|
||||
} else if (command.equals("setteam")) {
|
||||
this.performSetTeam(player, arguments);
|
||||
} else if (command.equals("setteamflag")) {
|
||||
this.performSetTeamFlag(player, arguments);
|
||||
} else if (command.equals("deleteteam")) {
|
||||
this.performDeleteTeam(player, arguments);
|
||||
} else if (command.equals("setmonument")) {
|
||||
this.performSetMonument(player, arguments);
|
||||
} else if (command.equals("setwarconfig") || command.equals("warcfg")) {
|
||||
this.performSetWarConfig(player, arguments);
|
||||
} else if (command.equals("zonemaker") || command.equals("zm")) {
|
||||
@ -327,65 +319,6 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void performSetTeamFlag(Player player, String[] arguments) {
|
||||
if (arguments.length < 1 || !this.inAnyWarzone(player.getLocation()) || (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) {
|
||||
this.badMsg(player, "Usage: /setteamflag <team-name/color>, e.g. /setteamflag diamond. " + "Sets the team flag post to the current location. " + "Must be in a warzone (try /zones and /zone). ");
|
||||
} else {
|
||||
TeamKind kind = TeamKinds.teamKindFromString(arguments[0]);
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
Team team = warzone.getTeamByKind(kind);
|
||||
if (team == null) {
|
||||
// no such team yet
|
||||
this.badMsg(player, "Place the team spawn first.");
|
||||
} else if (team.getFlagVolume() == null) {
|
||||
// new team flag
|
||||
team.setTeamFlag(player.getLocation());
|
||||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ()));
|
||||
this.msg(player, "Team " + team.getName() + " flag added here.");
|
||||
WarzoneMapper.save(warzone, false);
|
||||
} else {
|
||||
// relocate flag
|
||||
team.getFlagVolume().resetBlocks();
|
||||
team.setTeamFlag(player.getLocation());
|
||||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1));
|
||||
this.msg(player, "Team " + team.getName() + " flag moved.");
|
||||
WarzoneMapper.save(warzone, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void performSetTeam(Player player, String[] arguments) {
|
||||
if (arguments.length < 1 || !this.inAnyWarzone(player.getLocation()) || (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) {
|
||||
this.badMsg(player, "Usage: /setteam <team-kind/color>, e.g. /setteam red." + "Sets the team spawn to the current location. " + "Must be in a warzone (try /zones and /zone). ");
|
||||
} else {
|
||||
TeamKind teamKind = TeamKinds.teamKindFromString(arguments[0]);
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
Team existingTeam = warzone.getTeamByKind(teamKind);
|
||||
if (existingTeam != null) {
|
||||
// relocate
|
||||
existingTeam.setTeamSpawn(player.getLocation());
|
||||
this.msg(player, "Team " + existingTeam.getName() + " spawn relocated.");
|
||||
} else {
|
||||
// new team (use default TeamKind name for now)
|
||||
Team newTeam = new Team(teamKind.getDefaultName(), teamKind, player.getLocation(), warzone);
|
||||
newTeam.setRemainingLives(warzone.getLifePool());
|
||||
warzone.getTeams().add(newTeam);
|
||||
if (warzone.getLobby() != null) {
|
||||
warzone.getLobby().getVolume().resetBlocks();
|
||||
// warzone.getVolume().resetWallBlocks(warzone.getLobby().getWall());
|
||||
// warzone.addZoneOutline(warzone.getLobby().getWall());
|
||||
warzone.getLobby().initialize();
|
||||
}
|
||||
newTeam.setTeamSpawn(player.getLocation());
|
||||
this.msg(player, "Team " + newTeam.getName() + " created with spawn here.");
|
||||
}
|
||||
|
||||
WarzoneMapper.save(warzone, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void performSetZoneConfig(Player player, String[] arguments) {
|
||||
if ((!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) || arguments.length == 0) {
|
||||
this.badMsg(player, "Usage: /setzoneconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + "Please give at leaset one named parameter. Does not save the blocks of the warzone. Resets the zone with the new config. Must be in warzone.");
|
||||
|
@ -61,9 +61,18 @@ public class WarCommandHandler {
|
||||
else if (command.equals("nextbattle")) {
|
||||
commandObj = new NextbattleCommand(this, sender, arguments);
|
||||
}
|
||||
else if (command.equals("setteam")) {
|
||||
commandObj = new SetteamCommand(this, sender, arguments);
|
||||
}
|
||||
else if (command.equals("deleteteam")) {
|
||||
commandObj = new DeleteteamCommand(this, sender, arguments);
|
||||
}
|
||||
else if (command.equals("teamflag")) {
|
||||
commandObj = new SetteamflagCommand(this, sender, arguments);
|
||||
}
|
||||
else if (command.equals("setmonument")) {
|
||||
commandObj = new SetmonumentCommand(this, sender, arguments);
|
||||
}
|
||||
else if (command.equals("deletemonument")) {
|
||||
commandObj = new DeletemonumentCommand(this, sender, arguments);
|
||||
}
|
||||
|
@ -20,11 +20,10 @@ public class DeletemonumentCommand extends AbstractZoneMakerCommand {
|
||||
Warzone zone;
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
else if (this.args.length == 2) {
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else {
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@ -34,6 +33,8 @@ public class DeletemonumentCommand extends AbstractZoneMakerCommand {
|
||||
if (lobby == null) return false;
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
|
@ -21,11 +21,10 @@ public class DeleteteamCommand extends AbstractZoneMakerCommand {
|
||||
Warzone zone;
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
else if (this.args.length == 2) {
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else {
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@ -35,6 +34,8 @@ public class DeleteteamCommand extends AbstractZoneMakerCommand {
|
||||
if (lobby == null) return false;
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
|
@ -18,6 +18,9 @@ public class DeletewarhubCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
if (War.war.getWarHub() != null) {
|
||||
// reset existing hub
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
|
@ -21,9 +21,10 @@ public class DeletezoneCommand extends AbstractZoneMakerCommand {
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else {
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@ -33,6 +34,8 @@ public class DeletezoneCommand extends AbstractZoneMakerCommand {
|
||||
if (lobby == null) return false;
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
|
@ -32,20 +32,23 @@ public class JoinCommand extends AbstractWarCommand {
|
||||
Warzone zone;
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
else if (this.args.length == 2) {
|
||||
} else if (this.args.length == 2) {
|
||||
// zone by name
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
// move the team-name to first place :)
|
||||
this.args[0] = this.args[1];
|
||||
}
|
||||
else {
|
||||
zone = Warzone.getZoneByLocation(player);
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.sender);
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation(player);
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.sender);
|
||||
if (lobby == null) return false;
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
|
@ -16,6 +16,10 @@ public class LeaveCommand extends AbstractWarCommand {
|
||||
public boolean handle() {
|
||||
if (!(this.sender instanceof Player)) return true;
|
||||
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player) this.sender;
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone == null) {
|
||||
|
@ -12,6 +12,9 @@ public class LoadwarCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
War.war.loadWar();
|
||||
|
||||
return true;
|
||||
|
@ -18,7 +18,7 @@ public class NextbattleCommand extends AbstractZoneMakerCommand {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else {
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@ -28,6 +28,8 @@ public class NextbattleCommand extends AbstractZoneMakerCommand {
|
||||
if (lobby == null) return false;
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
|
@ -19,7 +19,7 @@ public class ResetzoneCommand extends AbstractZoneMakerCommand {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else {
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@ -29,6 +29,8 @@ public class ResetzoneCommand extends AbstractZoneMakerCommand {
|
||||
if (lobby == null) return false;
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
|
@ -19,6 +19,9 @@ public class SetwarhubCommand extends AbstractZoneMakerCommand {
|
||||
public boolean handle() {
|
||||
if (!(this.sender instanceof Player)) return true;
|
||||
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.sender;
|
||||
|
||||
if (War.war.getWarzones().size() > 0) {
|
||||
|
@ -18,7 +18,7 @@ public class TeamsCommand extends AbstractWarCommand {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else {
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@ -28,6 +28,8 @@ public class TeamsCommand extends AbstractWarCommand {
|
||||
if (lobby == null) return false;
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
|
@ -12,6 +12,10 @@ public class UnloadwarCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
War.war.unloadWar();
|
||||
|
||||
return true;
|
||||
|
@ -16,7 +16,9 @@ public class WarhubCommand extends AbstractWarCommand {
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.sender instanceof Player)) return true;
|
||||
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.sender;
|
||||
if (War.war.getWarHub() == null) {
|
||||
this.msg("No warhub on this War server. Try /zones and /zone.");
|
||||
|
@ -15,14 +15,14 @@ public class WarzoneCommand extends AbstractWarCommand {
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
// ignore it when no player
|
||||
if (!(this.sender instanceof Player)) return true;
|
||||
|
||||
Player player = (Player) this.sender;
|
||||
if (this.args.length < 1) {
|
||||
// handle missing warzone-name
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
} else if (!War.war.canWarp(player)) {
|
||||
}
|
||||
Player player = (Player) this.sender;
|
||||
|
||||
if (!War.war.canWarp(player)) {
|
||||
this.msg("Can't warp to zone. You need the 'war.warp' permission.");
|
||||
} else {
|
||||
Warzone warzone = Warzone.getZoneByName(this.args[0]);
|
||||
|
@ -21,6 +21,9 @@ public class WarzonesCommand extends AbstractWarCommand {
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
String warzonesMessage = "Warzones: ";
|
||||
if (War.war.getWarzones().isEmpty()) {
|
||||
warzonesMessage += "none.";
|
||||
|
Loading…
Reference in New Issue
Block a user