From ccf78bd9515aa302ea68fa2c79328ed67b8b503d Mon Sep 17 00:00:00 2001 From: taoneill Date: Sat, 16 Jul 2011 12:27:13 -0400 Subject: [PATCH] Closes gh-189. Closes gh-245. Closes gh-248. New on/off settings for /warcfg and /zonecfg: resetOnEmpty, resetOnLoad, resetOnUnload. Use resetonempty to for a warzone reset when the last player leaves. All default to false. Nice thing I should've done from the start: Op is zonemaker by default. --- .../main/java/bukkit/tommytony/war/War.java | 68 +++++++++++++++++-- .../main/java/com/tommytony/war/Warzone.java | 39 ++++++++++- .../war/jobs/RestoreWarzonesJob.java | 5 +- .../com/tommytony/war/mappers/WarMapper.java | 18 +++++ .../tommytony/war/mappers/WarzoneMapper.java | 18 +++++ 5 files changed, 139 insertions(+), 9 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index 2e68caf..6c41dad 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -55,6 +55,8 @@ public class War extends JavaPlugin { private final List zoneMakersImpersonatingPlayers = new ArrayList(); private HashMap disconnected = new HashMap(); private final HashMap wandBearers = new HashMap(); // playername to zonename + + // Default warzone settings private final HashMap defaultLoadout = new HashMap(); private int defaultLifepool = 21; private boolean defaultFriendlyFire = false; @@ -68,11 +70,15 @@ public class War extends JavaPlugin { private final HashMap defaultReward = new HashMap(); private boolean defaultUnbreakableZoneBlocks = false; private boolean defaultNoCreatures = false; + private boolean defaultResetOnEmpty = false; + private boolean defaultResetOnLoad = false; + private boolean defaultResetOnUnload = false; + // Global settings private boolean pvpInZonesOnly = false; - private boolean buildInZonesOnly = false; - private boolean disablePvpMessage = false; + private boolean buildInZonesOnly = false; + private WarHub warHub; @@ -322,7 +328,7 @@ public class War extends JavaPlugin { public void performSetWarConfig(Player player, String[] arguments) { if(arguments.length == 0) { this.badMsg(player, "Usage: /setwarconfig pvpinzonesonly:on lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + - "Changes the server defaults for new warzones. Please give at leaset one named parameter. Must be in warzone."); + "Changes the server defaults for new warzones. Please give at leaset one named parameter."); } else { if(updateFromNamedParams(player, arguments)) { WarMapper.save(this); @@ -1066,6 +1072,18 @@ public class War extends JavaPlugin { //String rewardType = namedParams.get("reward"); inventoryToLoadout(player, warzone.getReward()); } + if(namedParams.containsKey("resetonempty")) { + String onOff = namedParams.get("resetonempty"); + warzone.setResetOnEmpty(onOff.equals("on") || onOff.equals("true")); + } + if(namedParams.containsKey("resetonload")) { + String onOff = namedParams.get("resetonload"); + warzone.setResetOnLoad(onOff.equals("on") || onOff.equals("true")); + } + if(namedParams.containsKey("resetonunload")) { + String onOff = namedParams.get("resetonunload"); + warzone.setResetOnUnload(onOff.equals("on") || onOff.equals("true")); + } // if(namedParams.containsKey("dropLootOnDeath")){ // String onOff = namedParams.get("dropLootOnDeath"); // warzone.setDropLootOnDeath(onOff.equals("on") || onOff.equals("true")); @@ -1147,6 +1165,18 @@ public class War extends JavaPlugin { //String rewardType = namedParams.get("reward"); inventoryToLoadout(player, this.getDefaultReward()); } + if(namedParams.containsKey("resetonempty")) { + String onOff = namedParams.get("resetonempty"); + setDefaultResetOnEmpty(onOff.equals("on") || onOff.equals("true")); + } + if(namedParams.containsKey("resetonload")) { + String onOff = namedParams.get("resetonload"); + setDefaultResetOnLoad(onOff.equals("on") || onOff.equals("true")); + } + if(namedParams.containsKey("resetonunload")) { + String onOff = namedParams.get("resetonunload"); + setDefaultResetOnUnload(onOff.equals("on") || onOff.equals("true")); + } if(namedParams.containsKey("rallypoint")) { //String rewardType = namedParams.get("reward"); setZoneRallyPoint(namedParams.get("rallypoint"), player); @@ -1402,8 +1432,9 @@ public class War extends JavaPlugin { || War.permissionHandler.has(player, "War.build"))) { return true; } - // w/o Permissions, if buildInZonesOnly, no one can build outside the zone - return false; + // w/o Permissions, if buildInZonesOnly, no one can build outside the zone except Zonemakers + if(isZoneMaker(player)) return true; + else return false; } else { return true; } @@ -1429,6 +1460,9 @@ public class War extends JavaPlugin { if(disguised.equals(player.getName())) isPlayerImpersonator = true; } if(!isPlayerImpersonator) { + if(player.isOp()) { + return true; + } for(String zoneMaker : zoneMakerNames) { if(zoneMaker.equals(player.getName())) return true; } @@ -1608,4 +1642,28 @@ public class War extends JavaPlugin { return loaded; } + public void setDefaultResetOnEmpty(boolean defaultResetOnEmpty) { + this.defaultResetOnEmpty = defaultResetOnEmpty; + } + + public boolean isDefaultResetOnEmpty() { + return defaultResetOnEmpty; + } + + public void setDefaultResetOnLoad(boolean defaultResetOnLoad) { + this.defaultResetOnLoad = defaultResetOnLoad; + } + + public boolean isDefaultResetOnLoad() { + return defaultResetOnLoad; + } + + public void setDefaultResetOnUnload(boolean defaultResetOnUnload) { + this.defaultResetOnUnload = defaultResetOnUnload; + } + + public boolean isDefaultResetOnUnload() { + return defaultResetOnUnload; + } + } diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 40b64dc..c07e328 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -56,7 +56,11 @@ public class Warzone { private boolean unbreakableZoneBlocks; private boolean disabled = false; private boolean noCreatures; + private boolean resetOnEmpty = false; + private boolean resetOnLoad = false; + private boolean resetOnUnload = false; + private HashMap deadMenInventories = new HashMap(); private Location rallyPoint; @@ -75,6 +79,9 @@ public class Warzone { this.setDropLootOnDeath(war.isDefaultDropLootOnDeath()); this.setUnbreakableZoneBlocks(war.isDefaultUnbreakableZoneBlocks()); this.setNoCreatures(war.getDefaultNoCreatures()); + this.setResetOnEmpty(war.isDefaultResetOnEmpty()); + this.setResetOnLoad(war.isDefaultResetOnLoad()); + this.setResetOnUnload(war.isDefaultResetOnUnload()); this.volume = new ZoneVolume(name, war, this.getWorld(), this); } @@ -861,7 +868,7 @@ public class Warzone { break; } } - if(zoneEmpty && resetOnEmpty) { + if(zoneEmpty && isResetOnEmpty()) { // reset the zone for a new game when the last player leaves for(Team team : this.getTeams()) { team.resetPoints(); @@ -1020,7 +1027,7 @@ public class Warzone { } public void unload() { - war.logInfo("Clearing zone " + this.getName() + "..."); + war.logInfo("Unloading zone " + this.getName() + "..."); for(Team team : this.getTeams()) { for(Player player : team.getPlayers()) { this.handlePlayerLeave(player, this.getTeleport(), false); @@ -1032,7 +1039,33 @@ public class Warzone { this.getLobby().getVolume().resetBlocks(); this.getLobby().getVolume().finalize(); } - //this.getVolume().resetBlocks(); + if(this.isResetOnUnload()) { + this.getVolume().resetBlocks(); + } this.getVolume().finalize(); } + + public void setResetOnLoad(boolean resetOnLoad) { + this.resetOnLoad = resetOnLoad; + } + + public boolean isResetOnLoad() { + return resetOnLoad; + } + + public void setResetOnUnload(boolean resetOnUnload) { + this.resetOnUnload = resetOnUnload; + } + + public boolean isResetOnUnload() { + return resetOnUnload; + } + + public void setResetOnEmpty(boolean resetOnEmpty) { + this.resetOnEmpty = resetOnEmpty; + } + + public boolean isResetOnEmpty() { + return resetOnEmpty; + } } diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java index 64eed13..3f96b53 100644 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java @@ -22,7 +22,7 @@ public class RestoreWarzonesJob implements Runnable { war.getWarzones().clear(); for(String warzoneName : warzoneSplit) { if(warzoneName != null && !warzoneName.equals("")){ - war.logInfo("Restoring zone " + warzoneName + "..."); + war.logInfo("Loading zone " + warzoneName + "..."); Warzone zone = WarzoneMapper.load(war, warzoneName, !newWarInstall); if(zone != null) { // could have failed, would've been logged already war.getWarzones().add(zone); @@ -31,6 +31,9 @@ public class RestoreWarzonesJob implements Runnable { if(zone.getLobby() != null) { zone.getLobby().getVolume().resetBlocks(); } + if(zone.isResetOnLoad()) { + zone.getVolume().resetBlocks(); + } zone.initializeZone(); } } diff --git a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java index f1c5ac8..3f48600 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java @@ -144,6 +144,15 @@ public class WarMapper { // defaultDropLootOnDeath //war.setDefaultDropLootOnDeath(warConfig.getBoolean("defaultDropLootOnDeath")); + // defaultResetOnEmpty + war.setDefaultResetOnEmpty(warConfig.getBoolean("defaultResetOnEmpty")); + + // defaultResetOnLoad + war.setDefaultResetOnLoad(warConfig.getBoolean("defaultResetOnLoad")); + + // defaultResetOnUnload + war.setDefaultResetOnUnload(warConfig.getBoolean("defaultResetOnUnload")); + // warhub String hubStr = warConfig.getString("warhub"); if(hubStr != null && !hubStr.equals("")) { @@ -234,6 +243,15 @@ public class WarMapper { // defaultNoCreatures warConfig.setBoolean("defaultNoCreatures", war.isDefaultNoCreatures()); + // defaultResetOnEmpty + warConfig.setBoolean("defaultResetOnEmpty", war.isDefaultResetOnEmpty()); + + // defaultResetOnLoad + warConfig.setBoolean("defaultResetOnLoad", war.isDefaultResetOnLoad()); + + // defaultResetOnUnload + warConfig.setBoolean("defaultResetOnUnload", war.isDefaultResetOnUnload()); + // defaultDropLootOnDeath //warConfig.setBoolean("defaultDropLootOnDeath", war.isDefaultDropLootOnDeath()); diff --git a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java index e7fe646..9d50ad1 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -199,6 +199,15 @@ public class WarzoneMapper { // defaultNoCreatures warzone.setNoCreatures(warzoneConfig.getBoolean("noCreatures")); + // resetOnEmpty + warzone.setResetOnEmpty(warzoneConfig.getBoolean("resetOnEmpty")); + + // resetOnLoad + warzone.setResetOnLoad(warzoneConfig.getBoolean("resetOnLoad")); + + // resetOnUnload + warzone.setResetOnUnload(warzoneConfig.getBoolean("resetOnUnload")); + // rallyPoint String rallyPointStr = warzoneConfig.getString("rallyPoint"); if(rallyPointStr != null && !rallyPointStr.equals("")) { @@ -388,6 +397,15 @@ public class WarzoneMapper { // noCreatures warzoneConfig.setBoolean("noCreatures", warzone.isNoCreatures()); + // resetOnEmpty + warzoneConfig.setBoolean("resetOnEmpty", warzone.isResetOnEmpty()); + + // resetOnLoad + warzoneConfig.setBoolean("resetOnLoad", warzone.isResetOnLoad()); + + // resetOnUnload + warzoneConfig.setBoolean("resetOnUnload", warzone.isResetOnUnload()); + // rallyPoint String rpStr = ""; Location rp = warzone.getRallyPoint();