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.

This commit is contained in:
taoneill 2011-07-16 12:27:13 -04:00
parent f4c1eca815
commit ccf78bd951
5 changed files with 139 additions and 9 deletions

View File

@ -55,6 +55,8 @@ public class War extends JavaPlugin {
private final List<String> zoneMakersImpersonatingPlayers = new ArrayList<String>();
private HashMap<String, InventoryStash> disconnected = new HashMap<String, InventoryStash>();
private final HashMap<String, String> wandBearers = new HashMap<String, String>(); // playername to zonename
// Default warzone settings
private final HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
private int defaultLifepool = 21;
private boolean defaultFriendlyFire = false;
@ -68,11 +70,15 @@ public class War extends JavaPlugin {
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
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;
}
}

View File

@ -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<String, InventoryStash> deadMenInventories = new HashMap<String, InventoryStash>();
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;
}
}

View File

@ -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();
}
}

View File

@ -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());

View File

@ -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();