Added /savezone and /zonecfg commands that work from outside the zone. Better matching to support exact matches when looking for a warzone by name. Invisible spawn setting can be set as default spawn style now. Rallypoint stays with /warcfg. Whew.

This commit is contained in:
taoneill 2011-08-06 19:04:18 -04:00
parent 6dfb485ec2
commit ec35b6088a
8 changed files with 245 additions and 120 deletions

View File

@ -178,18 +178,6 @@ public class War extends JavaPlugin {
*/
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
return this.commandHandler.handle(sender, cmd, args);
/*
if (this.isZoneMaker(player)) {
// Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone
if (command.equals("savezone")) {
this.performSaveZone(player, arguments);
} else if (command.equals("setzoneconfig") || command.equals("zonecfg")) {
this.performSetZoneConfig(player, arguments);
}
}
return true;
*/
}
/**
@ -229,71 +217,7 @@ public class War extends JavaPlugin {
this.inventoryToLoadout(player.getInventory(), loadout);
}
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.");
} else {
Warzone warzone = Warzone.getZoneByLocation(player);
ZoneLobby lobby = ZoneLobby.getLobbyByLocation(player);
if (warzone == null && lobby != null) {
warzone = lobby.getZone();
} else {
lobby = warzone.getLobby();
}
if (this.updateZoneFromNamedParams(warzone, player, arguments)) {
this.msg(player, "Saving config and resetting warzone " + warzone.getName() + ".");
WarzoneMapper.save(warzone, false);
warzone.getVolume().resetBlocks();
if (lobby != null) {
lobby.getVolume().resetBlocks();
}
warzone.initializeZone(); // bring back team spawns etc
this.msg(player, "Warzone config saved. Zone reset.");
if (this.warHub != null) { // maybe the zone was disabled/enabled
this.warHub.getVolume().resetBlocks();
this.warHub.initialize();
}
} else {
this.badMsg(player, "Failed to read named parameters.");
}
}
}
public void performSaveZone(Player player, String[] arguments) {
if (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) {
this.badMsg(player, "Usage: /savezone lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + "All named params optional. Saves the blocks of the warzone (i.e. the current zone state will be reloaded at each battle start). Must be in warzone.");
} else {
Warzone warzone = Warzone.getZoneByLocation(player);
ZoneLobby lobby = ZoneLobby.getLobbyByLocation(player);
if (warzone == null && lobby != null) {
warzone = lobby.getZone();
} else {
lobby = warzone.getLobby();
}
this.msg(player, "Saving warzone " + warzone.getName() + ".");
int savedBlocks = warzone.saveState(true);
if (arguments.length > 0) {
// changed settings: must reinitialize with new settings
this.updateZoneFromNamedParams(warzone, player, arguments);
WarzoneMapper.save(warzone, true);
warzone.getVolume().resetBlocks();
if (lobby != null) {
lobby.getVolume().resetBlocks();
}
warzone.initializeZone(); // bring back team spawns etc
if (this.warHub != null) { // maybe the zone was disabled/enabled
this.warHub.getVolume().resetBlocks();
this.warHub.initialize();
}
}
this.msg(player, "Warzone " + warzone.getName() + " initial state changed. Saved " + savedBlocks + " blocks.");
}
}
private boolean updateZoneFromNamedParams(Warzone warzone, Player player, String[] arguments) {
public boolean updateZoneFromNamedParams(Warzone warzone, CommandSender commandSender, String[] arguments) {
try {
Map<String, String> namedParams = new HashMap<String, String>();
for (String namedPair : arguments) {
@ -350,12 +274,7 @@ public class War extends JavaPlugin {
String onOff = namedParams.get("nocreatures");
warzone.setNoCreatures(onOff.equals("on") || onOff.equals("true"));
}
if (namedParams.containsKey("loadout")) {
this.inventoryToLoadout(player, warzone.getLoadout());
}
if (namedParams.containsKey("reward")) {
this.inventoryToLoadout(player, warzone.getReward());
}
if (namedParams.containsKey("resetonempty")) {
String onOff = namedParams.get("resetonempty");
warzone.setResetOnEmpty(onOff.equals("on") || onOff.equals("true"));
@ -368,6 +287,15 @@ public class War extends JavaPlugin {
String onOff = namedParams.get("resetonunload");
warzone.setResetOnUnload(onOff.equals("on") || onOff.equals("true"));
}
if (commandSender instanceof Player) {
Player player = (Player) commandSender;
if (namedParams.containsKey("loadout")) {
this.inventoryToLoadout(player, warzone.getLoadout());
}
if (namedParams.containsKey("reward")) {
this.inventoryToLoadout(player, warzone.getReward());
}
}
return true;
} catch (Exception e) {
@ -375,7 +303,7 @@ public class War extends JavaPlugin {
}
}
public boolean updateFromNamedParams(Player player, String[] arguments) {
public boolean updateFromNamedParams(CommandSender commandSender, String[] arguments) {
try {
Map<String, String> namedParams = new HashMap<String, String>();
for (String namedPair : arguments) {
@ -422,6 +350,8 @@ public class War extends JavaPlugin {
this.setDefaultSpawnStyle(spawnStyle);
} else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) {
this.setDefaultSpawnStyle(spawnStyle);
} else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)) {
this.setDefaultSpawnStyle(spawnStyle);
} else {
this.setDefaultSpawnStyle(TeamSpawnStyles.BIG);
}
@ -438,12 +368,7 @@ public class War extends JavaPlugin {
String onOff = namedParams.get("nocreatures");
this.setDefaultNoCreatures(onOff.equals("on") || onOff.equals("true"));
}
if (namedParams.containsKey("loadout")) {
this.inventoryToLoadout(player, this.getDefaultLoadout());
}
if (namedParams.containsKey("reward")) {
this.inventoryToLoadout(player, this.getDefaultReward());
}
if (namedParams.containsKey("resetonempty")) {
String onOff = namedParams.get("resetonempty");
this.setDefaultResetOnEmpty(onOff.equals("on") || onOff.equals("true"));
@ -456,8 +381,17 @@ public class War extends JavaPlugin {
String onOff = namedParams.get("resetonunload");
this.setDefaultResetOnUnload(onOff.equals("on") || onOff.equals("true"));
}
if (namedParams.containsKey("rallypoint")) {
this.setZoneRallyPoint(namedParams.get("rallypoint"), player);
if (commandSender instanceof Player) {
Player player = (Player)commandSender;
if (namedParams.containsKey("loadout")) {
this.inventoryToLoadout(player, this.getDefaultLoadout());
}
if (namedParams.containsKey("reward")) {
this.inventoryToLoadout(player, this.getDefaultReward());
}
if (namedParams.containsKey("rallypoint")) {
this.setZoneRallyPoint(namedParams.get("rallypoint"), player);
}
}
return true;

View File

@ -68,6 +68,8 @@ public class WarCommandHandler {
commandObj = new DeleteZoneCommand(this, sender, arguments);
} else if (command.equals("setzonelobby")) {
commandObj = new SetZoneLobbyCommand(this, sender, arguments);
} else if (command.equals("savezone")) {
commandObj = new SaveZoneCommand(this, sender, arguments);
} else if (command.equals("resetzone")) {
commandObj = new ResetZoneCommand(this, sender, arguments);
} else if (command.equals("nextbattle")) {
@ -82,6 +84,8 @@ public class WarCommandHandler {
commandObj = new SetMonumentCommand(this, sender, arguments);
} else if (command.equals("deletemonument")) {
commandObj = new DeleteMonumentCommand(this, sender, arguments);
} else if (command.equals("setzoneconfig") || command.equals("zonecfg")) {
commandObj = new SetZoneConfigCommand(this, sender, arguments);
} else if (command.equals("setwarhub")) {
commandObj = new SetWarHubCommand(this, sender, arguments);
} else if (command.equals("deletewarhub")) {

View File

@ -0,0 +1,89 @@
package bukkit.tommytony.war.command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.Warzone;
import com.tommytony.war.ZoneLobby;
import com.tommytony.war.mappers.WarMapper;
import com.tommytony.war.mappers.WarzoneMapper;
import bukkit.tommytony.war.War;
import bukkit.tommytony.war.WarCommandHandler;
public class SaveZoneCommand extends AbstractZoneMakerCommand {
public SaveZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
super(handler, sender, args);
}
@Override
public boolean handle() {
Warzone zone = null;
CommandSender commandSender = this.getSender();
boolean isFirstParamWarzone = false;
if(this.args.length > 0 && !this.args[0].contains(":")) {
// warzone name maybe in first place
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
if (zoneByName != null) {
zone = zoneByName;
isFirstParamWarzone = true;
}
}
if (this.getSender() instanceof Player) {
Player player = (Player)commandSender;
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
if(zoneByLoc == null && lobbyByLoc != null) {
zoneByLoc = lobbyByLoc.getZone();
}
if(zoneByLoc != null) {
zone = zoneByLoc;
}
}
if (zone == null) {
// No warzone found, whatever the mean, escape
return false;
}
if (isFirstParamWarzone) {
if(this.args.length > 1) {
// More than one param: the arguments need to be shifted
String[] newargs = new String[this.args.length - 1];
for (int i = 1; i < this.args.length; i++) {
newargs[i-1] = args[i];
}
this.args = newargs;
}
}
// We have a warzone and indexed-from-0 arguments, let's updatethis.msg(player, "Saving warzone " + warzone.getName() + ".");
int savedBlocks = zone.saveState(true);
// changed settings: must reinitialize with new settings
War.war.updateZoneFromNamedParams(zone, commandSender, args);
WarzoneMapper.save(zone, true);
if(this.args.length > 0) {
// the config may have changed, requiring a reset for spawn styles etc.
zone.getVolume().resetBlocks();
}
if (zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks();
}
zone.initializeZone(); // bring back team spawns etc
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize();
}
this.msg("Warzone " + zone.getName() + " initial state changed. Saved " + savedBlocks + " blocks.");
return true;
}
}

View File

@ -19,13 +19,8 @@ public class SetWarConfigCommand extends AbstractZoneMakerCommand {
if (this.args.length == 0) {
return false;
}
if (!(this.getSender() instanceof Player)) {
return true;
// TODO: Maybe move rallypoint to warzone setting
// TODO: The rallypoint is the only thing that prevents this from being used from cli
}
if (War.war.updateFromNamedParams((Player) this.getSender(), this.args)) {
if (War.war.updateFromNamedParams(this.getSender(), this.args)) {
WarMapper.save();
this.msg("War config saved.");
} else {

View File

@ -0,0 +1,92 @@
package bukkit.tommytony.war.command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.Warzone;
import com.tommytony.war.ZoneLobby;
import com.tommytony.war.mappers.WarMapper;
import com.tommytony.war.mappers.WarzoneMapper;
import bukkit.tommytony.war.War;
import bukkit.tommytony.war.WarCommandHandler;
public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
public SetZoneConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
super(handler, sender, args);
}
@Override
public boolean handle() {
Warzone zone = null;
Player player = null;
CommandSender commandSender = this.getSender();
boolean isFirstParamWarzone = false;
if (this.args.length == 0) {
return false;
} else {
if(!this.args[0].contains(":")) {
// warzone name maybe in first place
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
if (zoneByName != null) {
zone = zoneByName;
isFirstParamWarzone = true;
}
}
if (this.getSender() instanceof Player) {
player = (Player)commandSender;
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
if(zoneByLoc == null && lobbyByLoc != null) {
zoneByLoc = lobbyByLoc.getZone();
}
if(zoneByLoc != null) {
zone = zoneByLoc;
}
}
if (zone == null) {
// No warzone found, whatever the mean, escape
return false;
}
if (isFirstParamWarzone) {
if(this.args.length == 1) {
// Only one param: the warzone name - default to usage
return false;
}
// More than one param: the arguments need to be shifted
String[] newargs = new String[this.args.length - 1];
for (int i = 1; i < this.args.length; i++) {
newargs[i-1] = args[i];
}
this.args = newargs;
}
// We have a warzone and indexed-from-0 arguments, let's update
if (War.war.updateZoneFromNamedParams(zone, player, this.args)) {
this.msg("Saving config and resetting warzone " + zone.getName() + ".");
WarzoneMapper.save(zone, false);
zone.getVolume().resetBlocks();
if (zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks();
}
zone.initializeZone(); // bring back team spawns etc
this.msg("Warzone config saved. Zone reset.");
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize();
}
} else {
this.badMsg("Failed to read named parameters.");
}
return true;
}
}
}

View File

@ -85,12 +85,17 @@ public class Warzone {
}
public static Warzone getZoneByName(String name) {
Warzone bestGuess = null;
for (Warzone warzone : War.war.getWarzones()) {
if (warzone.getName().toLowerCase().startsWith(name.toLowerCase())) {
if (warzone.getName().toLowerCase().equals(name.toLowerCase())) {
// perfect match, return right away
return warzone;
} else if (warzone.getName().toLowerCase().startsWith(name.toLowerCase())) {
// prehaps there's a perfect match in the remaining zones, let's take this one aside
bestGuess = warzone;
}
}
return null;
return bestGuess;
}
public static Warzone getZoneByLocation(Location location) {
@ -935,6 +940,12 @@ public class Warzone {
}
}
public String printConfig() {
String cfg = "Warzone " + this.getName() + " config: ";
return null;
}
public void setBlockHeads(boolean blockHeads) {
this.blockHeads = blockHeads;
}

View File

@ -64,10 +64,10 @@ commands:
description: War> Persists changes made to the warzone since the last save. Config can be set with named parameters.
usage: Persists changes made to the warzone since the last save. Config can be set with named parameters. Provide a zone name if not standing in warzone or lobby.
Ex -
/savezone => Basic save,
/savezone lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small> unbreakable:on nocreatures:on disabled:on,
/savezone loadout:default => sets the respawn inventory to your current items,
/savezone reward:default => sets the winner's reward to your current items.
/savezone [zone-name] => Basic save - name optional if standing inside,
/savezone [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small> unbreakable:on nocreatures:on disabled:on,
/savezone [zone-name] loadout:default => sets the respawn inventory to your current items,
/savezone [zone-name] reward:default => sets the winner's reward to your current items.
setzonelobby:
description: War> Creates or changes the position of the warzone lobby.
usage: Creates or changes the position of the warzone lobby.
@ -117,16 +117,16 @@ commands:
description: War> Use named parameters to change the configuration of the warzone. Resets blocks like /nextbattle. Does not save zone blocks like /savezone.
usage: Use named parameters to change the configuration of the warzone. Resets blocks like /nextbattle. Does not save zone blocks like /savezone. Provide a zone name if not standing in warzone or lobby.
Ex -
/setzoneconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig loadout:default => sets the respawn inventory to your current items,
/setzoneconfig reward:default => sets the winner's reward to your current items
/setzoneconfig [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig [zone-name] loadout:default => sets the respawn inventory to your current items,
/setzoneconfig [zone-name] reward:default => sets the winner's reward to your current items
zonecfg:
description: War> Alias for /setzoneconfig
usage: Use named parameters to change the configuration of the warzone. Resets blocks like /nextbattle. Does not save zone blocks like /savezone. Provide a zone name if not standing in warzone or lobby.
Ex -
/setzoneconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig loadout:default => sets the respawn inventory to your current items,
/setzoneconfig reward:default => sets the winner's reward to your current items
/setzoneconfig [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig [zone-name] loadout:default => sets the respawn inventory to your current items,
/setzoneconfig [zone-name] reward:default => sets the winner's reward to your current items
zonemaker:
description: War> Toggles between player mode and zone maker mode. Or gives/removes access to zonemaker commands for another player.
usage: Toggles between player mode and zone maker mode. Or gives/removes access to zonemaker commands for another player.

View File

@ -64,10 +64,10 @@ commands:
description: War> Persists changes made to the warzone since the last save. Config can be set with named parameters.
usage: Persists changes made to the warzone since the last save. Config can be set with named parameters. Provide a zone name if not standing in warzone or lobby.
Ex -
/savezone => Basic save,
/savezone lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small> unbreakable:on nocreatures:on disabled:on,
/savezone loadout:default => sets the respawn inventory to your current items,
/savezone reward:default => sets the winner's reward to your current items.
/savezone [zone-name] => Basic save - name optional if standing inside,
/savezone [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small> unbreakable:on nocreatures:on disabled:on,
/savezone [zone-name] loadout:default => sets the respawn inventory to your current items,
/savezone [zone-name] reward:default => sets the winner's reward to your current items.
setzonelobby:
description: War> Creates or changes the position of the warzone lobby.
usage: Creates or changes the position of the warzone lobby.
@ -117,16 +117,16 @@ commands:
description: War> Use named parameters to change the configuration of the warzone. Resets blocks like /nextbattle. Does not save zone blocks like /savezone.
usage: Use named parameters to change the configuration of the warzone. Resets blocks like /nextbattle. Does not save zone blocks like /savezone. Provide a zone name if not standing in warzone or lobby.
Ex -
/setzoneconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig loadout:default => sets the respawn inventory to your current items,
/setzoneconfig reward:default => sets the winner's reward to your current items
/setzoneconfig [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig [zone-name] loadout:default => sets the respawn inventory to your current items,
/setzoneconfig [zone-name] reward:default => sets the winner's reward to your current items
zonecfg:
description: War> Alias for /setzoneconfig
usage: Use named parameters to change the configuration of the warzone. Resets blocks like /nextbattle. Does not save zone blocks like /savezone. Provide a zone name if not standing in warzone or lobby.
Ex -
/setzoneconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig loadout:default => sets the respawn inventory to your current items,
/setzoneconfig reward:default => sets the winner's reward to your current items
/setzoneconfig [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig [zone-name] loadout:default => sets the respawn inventory to your current items,
/setzoneconfig [zone-name] reward:default => sets the winner's reward to your current items
zonemaker:
description: War> Toggles between player mode and zone maker mode. Or gives/removes access to zonemaker commands for another player.
usage: Toggles between player mode and zone maker mode. Or gives/removes access to zonemaker commands for another player.