From e019890f1df3280b7cf9f03e4bcab1faf22247ae Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 8 Jan 2017 15:47:38 -0500 Subject: [PATCH] Add a flag that blocks the damage from withers. Doesn't cover the skull projectiles, just body damage. Fixes WORLDGUARD-3787. --- .../listener/WorldGuardEntityListener.java | 17 +++++++++++++++-- .../protection/flags/DefaultFlag.java | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index 3e4791b8..2e4b9e3a 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -462,8 +462,6 @@ public void onEntityExplode(EntityExplodeEvent event) { } // allow wither skull blocking since there is no dedicated flag atm if (wcfg.useRegions) { - RegionManager mgr = plugin.getGlobalRegionManager().get(world); - for (Block block : event.blockList()) { if (!plugin.getRegionContainer().createQuery().getApplicableRegions(block.getLocation()).allows(DefaultFlag.GHAST_FIREBALL)) { event.blockList().clear(); @@ -481,6 +479,15 @@ public void onEntityExplode(EntityExplodeEvent event) { event.blockList().clear(); return; } + if (wcfg.useRegions) { + for (Block block : event.blockList()) { + if (!plugin.getGlobalRegionManager().allows(DefaultFlag.WITHER_DAMAGE, block.getLocation())) { + event.blockList().clear(); + event.setCancelled(true); + return; + } + } + } } else { // unhandled entity if (wcfg.blockOtherExplosions) { @@ -691,6 +698,12 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { event.setCancelled(true); return; } + if (wcfg.useRegions) { + if (!plugin.getGlobalRegionManager().allows(DefaultFlag.WITHER_DAMAGE, location)) { + event.setCancelled(true); + return; + } + } } else if (/*ent instanceof Zombie && */event instanceof EntityBreakDoorEvent) { if (wcfg.blockZombieDoorDestruction) { event.setCancelled(true); diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java index e1c08da2..fcb7a189 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -75,6 +75,7 @@ public final class DefaultFlag { public static final StateFlag GHAST_FIREBALL = new StateFlag("ghast-fireball", true); public static final StateFlag FIREWORK_DAMAGE = new StateFlag("firework-damage", true); public static final StateFlag OTHER_EXPLOSION = new StateFlag("other-explosion", true); + public static final StateFlag WITHER_DAMAGE = new StateFlag("wither-damage", true); public static final StateFlag FIRE_SPREAD = new StateFlag("fire-spread", true); public static final StateFlag LAVA_FIRE = new StateFlag("lava-fire", true); public static final StateFlag LIGHTNING = new StateFlag("lightning", true); @@ -146,7 +147,7 @@ public final class DefaultFlag { public static final Flag[] flagsList = new Flag[] { PASSTHROUGH, BUILD, BLOCK_BREAK, BLOCK_PLACE, PVP, CHEST_ACCESS, PISTONS, TNT, LIGHTER, RIDE, USE, INTERACT, PLACE_VEHICLE, DESTROY_VEHICLE, DAMAGE_ANIMALS, SLEEP, - MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS, FIREWORK_DAMAGE, + MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS, FIREWORK_DAMAGE, WITHER_DAMAGE, CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD, DENY_MESSAGE, ENTRY_DENY_MESSAGE, EXIT_DENY_MESSAGE, EXIT_OVERRIDE, EXIT_VIA_TELEPORT, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,