From 10ae82999ba13ed2b96a24d41292297cb3ebde60 Mon Sep 17 00:00:00 2001 From: taoneill Date: Tue, 15 Feb 2011 09:44:16 -0500 Subject: [PATCH] Closes gh-58. Added unbreakableZoneBlocks setting. Zone makers are not affected. --- war/src/main/java/bukkit/tommytony/war/War.java | 17 +++++++++++++++++ .../bukkit/tommytony/war/WarBlockListener.java | 15 ++++++++++++--- .../main/java/com/tommytony/war/Warzone.java | 10 ++++++++++ .../com/tommytony/war/mappers/WarMapper.java | 5 +++++ .../tommytony/war/mappers/WarzoneMapper.java | 5 +++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index 69ae575..aee06e4 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -77,6 +77,7 @@ public class War extends JavaPlugin { private boolean defaultDropLootOnDeath = false; private String defaultSpawnStyle = TeamSpawnStyles.BIG; private final HashMap defaultReward = new HashMap(); + private boolean defaultUnbreakableZoneBlocks = false; private boolean pvpInZonesOnly = false; private boolean buildInZonesOnly = false; @@ -1056,6 +1057,10 @@ public class War extends JavaPlugin { warzone.setSpawnStyle(TeamSpawnStyles.BIG); } } + if(namedParams.containsKey("unbreakable")) { + String onOff = namedParams.get("unbreakable"); + warzone.setUnbreakableZoneBlocks(onOff.equals("on") || onOff.equals("true")); + } // if(namedParams.containsKey("dropLootOnDeath")){ // String onOff = namedParams.get("dropLootOnDeath"); // warzone.setDropLootOnDeath(onOff.equals("on") || onOff.equals("true")); @@ -1118,6 +1123,10 @@ public class War extends JavaPlugin { String onOff = namedParams.get("buildinzonesonly"); setBuildInZonesOnly(onOff.equals("on") || onOff.equals("true")); } + if(namedParams.containsKey("unbreakable")) { + String onOff = namedParams.get("unbreakable"); + setDefaultUnbreakableZoneBlocks(onOff.equals("on") || onOff.equals("true")); + } // if(namedParams.containsKey("dropLootOnDeath")){ // String onOff = namedParams.get("dropLootOnDeath"); // setDefaultDropLootOnDeath(onOff.equals("on") || onOff.equals("true")); @@ -1459,5 +1468,13 @@ public class War extends JavaPlugin { public boolean isBuildInZonesOnly() { return buildInZonesOnly; } + + public void setDefaultUnbreakableZoneBlocks(boolean defaultUnbreakableZoneBlocks) { + this.defaultUnbreakableZoneBlocks = defaultUnbreakableZoneBlocks; + } + + public boolean isDefaultUnbreakableZoneBlocks() { + return defaultUnbreakableZoneBlocks; + } } diff --git a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java index f8c9772..9a06d25 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java @@ -134,7 +134,7 @@ public class WarBlockListener extends BlockListener { event.setCancelled(true); return; } else { - event.setCancelled(false); + event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down return; } // let team members loot one block the spawn for monument captures @@ -165,7 +165,7 @@ public class WarBlockListener extends BlockListener { event.setCancelled(true); return; } - } + } // protect warzone lobbies if(block != null) { @@ -187,12 +187,21 @@ public class WarBlockListener extends BlockListener { } // buildInZonesOnly - if(war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ())) == null + Warzone blockZone = war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ())); + if(blockZone == null && war.isBuildInZonesOnly() && !war.canBuildOutsideZone(player)) { war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside."); event.setCancelled(true); return; } + + // unbreakableZoneBlocks + if(blockZone != null && blockZone.isUnbreakableZoneBlocks() && !isZoneMaker) { + // if the zone is unbreakable, no one but zone makers can break blocks + war.badMsg(player, "The blocks in this zone are unbreakable!"); + event.setCancelled(true); + return; + } } } diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 53df32e..00daff0 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -55,6 +55,7 @@ public class Warzone { private boolean autoAssignOnly; private boolean blockHeads; private boolean dropLootOnDeath; + private boolean unbreakableZoneBlocks; public Warzone(War war, World world, String name) { @@ -70,6 +71,7 @@ public class Warzone { this.scoreCap = war.getDefaultScoreCap(); this.setBlockHeads(war.isDefaultBlockHeads()); this.setDropLootOnDeath(war.isDefaultDropLootOnDeath()); + this.setUnbreakableZoneBlocks(war.isDefaultUnbreakableZoneBlocks()); this.volume = new VerticalVolume(name, war, this.getWorld()); } @@ -1104,5 +1106,13 @@ public class Warzone { return reward; } + public void setUnbreakableZoneBlocks(boolean unbreakableZoneBlocks) { + this.unbreakableZoneBlocks = unbreakableZoneBlocks; + } + + public boolean isUnbreakableZoneBlocks() { + return unbreakableZoneBlocks; + } + } 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 36e55e2..671f667 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java @@ -141,6 +141,8 @@ public class WarMapper { } } + // defaultUnbreakableZoneBlocks + war.setDefaultUnbreakableZoneBlocks(warConfig.getBoolean("defaultUnbreakableZoneBlocks")); // defaultDropLootOnDeath //war.setDefaultDropLootOnDeath(warConfig.getBoolean("defaultDropLootOnDeath")); @@ -245,6 +247,9 @@ public class WarMapper { defaultRewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";"; } warConfig.setString("defaultReward", defaultRewardStr); + + // defaultUnbreakableZoneBlocks + warConfig.setBoolean("defaultUnbreakableZoneBlocks", war.isDefaultUnbreakableZoneBlocks()); // 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 2c44a05..df6d8b7 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -208,6 +208,9 @@ public class WarzoneMapper { } } + // unbreakableZoneBlocks + warzone.setUnbreakableZoneBlocks(warzoneConfig.getBoolean("unbreakableZoneBlocks")); + // dropLootOnDeath //warzone.setDropLootOnDeath(warzoneConfig.getBoolean("dropLootOnDeath")); @@ -389,6 +392,8 @@ public class WarzoneMapper { } warzoneConfig.setString("reward", rewardStr); + // unbreakableZoneBlocks + warzoneConfig.setBoolean("unbreakableZoneBlocks", warzone.isUnbreakableZoneBlocks()); // defaultDropLootOnDeath //warzoneConfig.setBoolean("dropLootOnDeath", warzone.isDropLootOnDeath());