From 12fc1438c2deeb081669c7e2ebdb1860a9337c24 Mon Sep 17 00:00:00 2001 From: wizjany Date: Mon, 8 Aug 2016 10:39:40 -0400 Subject: [PATCH] Add explicit ender crystal protection. Fixes WORLDGUARD-2620. --- .../listener/EventAbstractionListener.java | 20 ++++++++++++++----- .../bukkit/listener/RegionFlagsListener.java | 20 ++++--------------- .../worldguard/bukkit/util/Entities.java | 5 ++++- .../worldguard/bukkit/util/Materials.java | 4 ++++ 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index eec64e83..86b6a8de 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -889,23 +889,36 @@ private static void handleBlockRightClick(T even // next to redstone, without plugins getting the clicked place event // (not sure if this actually still happens) Events.fireToCancel(event, new UseBlockEvent(event, cause, clicked.getLocation(), Material.TNT)); + + // Workaround for http://leaky.bukkit.org/issues/1034 + Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), Material.TNT)); + return; } // Handle created Minecarts if (item != null && Materials.isMinecart(item.getType())) { // TODO: Give a more specific Minecart type Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.MINECART)); + return; } // Handle created boats if (item != null && Materials.isBoat(item.getType())) { // TODO as above Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT)); + return; } // Handle created armor stands if (item != null && item.getType() == Materials.ARMOR_STAND) { Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.ARMOR_STAND)); + return; + } + + if (item != null && item.getType() == Materials.END_CRYSTAL) { /*&& placed.getType() == Material.BEDROCK) {*/ // in vanilla you can only place them on bedrock but who knows what plugins will add + // may be overprotective as a result, but better than being underprotective + Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.ENDER_CRYSTAL)); + return; } // Handle created spawn eggs @@ -918,6 +931,7 @@ private static void handleBlockRightClick(T even } Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), type)); } + return; } // Handle cocoa beans @@ -926,11 +940,7 @@ private static void handleBlockRightClick(T even if (!(faceClicked == BlockFace.DOWN || faceClicked == BlockFace.UP)) { Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), Material.COCOA)); } - } - - // Workaround for http://leaky.bukkit.org/issues/1034 - if (item != null && item.getType() == Material.TNT) { - Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), Material.TNT)); + return; } } diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionFlagsListener.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionFlagsListener.java index 71816254..8fc8303c 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionFlagsListener.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionFlagsListener.java @@ -25,6 +25,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent; import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent; +import com.sk89q.worldguard.bukkit.util.Entities; import com.sk89q.worldguard.bukkit.util.Materials; import com.sk89q.worldguard.protection.association.RegionAssociable; import com.sk89q.worldguard.protection.flags.DefaultFlag; @@ -61,10 +62,6 @@ public void onPlaceBlock(final PlaceBlockEvent event) { Block block; if ((block = event.getCause().getFirstBlock()) != null) { - // ================================================================ - // PISTONS flag - // ================================================================ - if (Materials.isPistonBlock(block.getType())) { event.filter(testState(query, DefaultFlag.PISTONS), false); } @@ -80,31 +77,22 @@ public void onBreakBlock(final BreakBlockEvent event) { Block block; if ((block = event.getCause().getFirstBlock()) != null) { - // ================================================================ - // PISTONS flag - // ================================================================ - if (Materials.isPistonBlock(block.getType())) { event.filter(testState(query, DefaultFlag.PISTONS), false); } } - // ================================================================ - // CREEPER_EXPLOSION flag - // ================================================================ - if (event.getCause().find(EntityType.CREEPER) != null) { // Creeper event.filter(testState(query, DefaultFlag.CREEPER_EXPLOSION), config.explosionFlagCancellation); } - // ================================================================ - // ENDERDRAGON_BLOCK_DAMAGE flag - // ================================================================ - if (event.getCause().find(EntityType.ENDER_DRAGON) != null) { // Enderdragon event.filter(testState(query, DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE), config.explosionFlagCancellation); } + if (event.getCause().find(Entities.enderCrystalType) != null) { // should be nullsafe even if enderCrystalType field is null + event.filter(testState(query, DefaultFlag.OTHER_EXPLOSION), config.explosionFlagCancellation); + } } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java index 9f031663..965a8d4b 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java @@ -182,6 +182,8 @@ public static boolean isNonPlayerCreature(Entity entity) { private static final EntityType armorStandType = Enums.findByValue(EntityType.class, "ARMOR_STAND"); + public static final EntityType enderCrystalType = + Enums.findByValue(EntityType.class, "ENDER_CRYSTAL"); /** * Test whether using the given entity should be considered "building" @@ -192,7 +194,8 @@ public static boolean isNonPlayerCreature(Entity entity) { */ public static boolean isConsideredBuildingIfUsed(Entity entity) { return entity instanceof Hanging - || entity.getType() == armorStandType; + || entity.getType() == armorStandType + || entity.getType() == enderCrystalType; } private static final EntityType tippedArrow = Enums.findByValue(EntityType.class, "TIPPED_ARROW"); diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index 7841f5ef..938a06eb 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -47,12 +47,16 @@ public final class Materials { private static final Set DAMAGE_EFFECTS = new HashSet(); public static Material ARMOR_STAND; + public static Material END_CRYSTAL; static { try { + // for backwards compatible access to material enum ARMOR_STAND = Material.ARMOR_STAND; + END_CRYSTAL = Material.END_CRYSTAL; } catch (NoSuchFieldError ignored) { ARMOR_STAND = null; + END_CRYSTAL = null; } ENTITY_ITEMS.put(EntityType.PAINTING, Material.PAINTING);