From ab274151d4575e1be753fc02029837b67da555f4 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 5 Nov 2012 11:27:35 -0800 Subject: [PATCH] Potential fix for WORLDGUARD-2263, mobs.block-{item-frame,painting}-destroy not working. --- .../bukkit/WorldGuardHangingListener.java | 100 ++++++++++-------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java index 7ccebe48..81c517df 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java @@ -35,6 +35,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; @@ -69,64 +70,71 @@ public void registerEvents() { } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onHangingingBreak(HangingBreakEvent breakEvent) { - if (!(breakEvent instanceof HangingBreakByEntityEvent)) { - return; - } - - HangingBreakByEntityEvent event = (HangingBreakByEntityEvent) breakEvent; + public void onHangingingBreak(HangingBreakEvent event) { Hanging hanging = event.getEntity(); World world = hanging.getWorld(); ConfigurationManager cfg = plugin.getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(world); - if (event.getRemover() instanceof Player) { - Player player = (Player) event.getRemover(); + if (event instanceof HangingBreakByEntityEvent) { + HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent) event; + if (entityEvent instanceof Player) { + Player player = (Player) entityEvent.getRemover(); - if (wcfg.getBlacklist() != null) { - if (hanging instanceof Painting - && !wcfg.getBlacklist().check( - new BlockBreakBlacklistEvent(plugin.wrapPlayer(player), - toVector(player.getLocation()), ItemID.PAINTING), false, false)) { - event.setCancelled(true); - return; - } else if (hanging instanceof ItemFrame - && !wcfg.getBlacklist().check( - new BlockBreakBlacklistEvent(plugin.wrapPlayer(player), - toVector(player.getLocation()), ItemID.ITEM_FRAME), false, false)) { - event.setCancelled(true); - return; + if (wcfg.getBlacklist() != null) { + if (hanging instanceof Painting + && !wcfg.getBlacklist().check( + new BlockBreakBlacklistEvent(plugin.wrapPlayer(player), + toVector(player.getLocation()), ItemID.PAINTING), false, false)) { + event.setCancelled(true); + return; + } else if (hanging instanceof ItemFrame + && !wcfg.getBlacklist().check( + new BlockBreakBlacklistEvent(plugin.wrapPlayer(player), + toVector(player.getLocation()), ItemID.ITEM_FRAME), false, false)) { + event.setCancelled(true); + return; + } } - } - if (wcfg.useRegions) { - if (!plugin.getGlobalRegionManager().canBuild(player, hanging.getLocation())) { - player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); + if (wcfg.useRegions) { + if (!plugin.getGlobalRegionManager().canBuild(player, hanging.getLocation())) { + player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); + event.setCancelled(true); + return; + } + } + } else { + if (entityEvent.getRemover() instanceof Creeper) { + if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) { + event.setCancelled(true); + return; + } + if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(DefaultFlag.CREEPER_EXPLOSION, hanging.getLocation())) { + event.setCancelled(true); + return; + } + } + + if (hanging instanceof Painting + && (wcfg.blockEntityPaintingDestroy + || (wcfg.useRegions + && !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_PAINTING_DESTROY, hanging.getLocation())))) { + event.setCancelled(true); + } else if (hanging instanceof ItemFrame + && (wcfg.blockEntityItemFrameDestroy + || (wcfg.useRegions + && !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, hanging.getLocation())))) { event.setCancelled(true); - return; } } } else { - if (event.getRemover() instanceof Creeper) { - if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) { - event.setCancelled(true); - return; - } - if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(DefaultFlag.CREEPER_EXPLOSION, hanging.getLocation())) { - event.setCancelled(true); - return; - } - } - - if (hanging instanceof Painting - && (wcfg.blockEntityPaintingDestroy - || (wcfg.useRegions - && !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_PAINTING_DESTROY, hanging.getLocation())))) { + // Explosions from mobs are not covered by HangingBreakByEntity + if (hanging instanceof Painting && wcfg.blockEntityPaintingDestroy + && event.getCause() == RemoveCause.EXPLOSION) { event.setCancelled(true); - } else if (hanging instanceof ItemFrame - && (wcfg.blockEntityItemFrameDestroy - || (wcfg.useRegions - && !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, hanging.getLocation())))) { + } else if (hanging instanceof ItemFrame && wcfg.blockEntityItemFrameDestroy + && event.getCause() == RemoveCause.EXPLOSION) { event.setCancelled(true); } } @@ -181,7 +189,7 @@ public void onEntityInteract(PlayerInteractEntityEvent event) { event.setCancelled(true); return; } - + if (entity instanceof ItemFrame && ((!plugin.getGlobalRegionManager().allows( DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, entity.getLocation())))) {