Potential fix for WORLDGUARD-2263, mobs.block-{item-frame,painting}-destroy not working.

This commit is contained in:
sk89q 2012-11-05 11:27:35 -08:00
parent aec1e3a529
commit ab274151d4

View File

@ -35,6 +35,7 @@
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
@ -69,64 +70,71 @@ public void registerEvents() {
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingingBreak(HangingBreakEvent breakEvent) { public void onHangingingBreak(HangingBreakEvent event) {
if (!(breakEvent instanceof HangingBreakByEntityEvent)) {
return;
}
HangingBreakByEntityEvent event = (HangingBreakByEntityEvent) breakEvent;
Hanging hanging = event.getEntity(); Hanging hanging = event.getEntity();
World world = hanging.getWorld(); World world = hanging.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager(); ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world); WorldConfiguration wcfg = cfg.get(world);
if (event.getRemover() instanceof Player) { if (event instanceof HangingBreakByEntityEvent) {
Player player = (Player) event.getRemover(); HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent) event;
if (entityEvent instanceof Player) {
Player player = (Player) entityEvent.getRemover();
if (wcfg.getBlacklist() != null) { if (wcfg.getBlacklist() != null) {
if (hanging instanceof Painting if (hanging instanceof Painting
&& !wcfg.getBlacklist().check( && !wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player), new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), ItemID.PAINTING), false, false)) { toVector(player.getLocation()), ItemID.PAINTING), false, false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} else if (hanging instanceof ItemFrame } else if (hanging instanceof ItemFrame
&& !wcfg.getBlacklist().check( && !wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player), new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), ItemID.ITEM_FRAME), false, false)) { toVector(player.getLocation()), ItemID.ITEM_FRAME), false, false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
}
} }
}
if (wcfg.useRegions) { if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, hanging.getLocation())) { if (!plugin.getGlobalRegionManager().canBuild(player, hanging.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); 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); event.setCancelled(true);
return;
} }
} }
} else { } else {
if (event.getRemover() instanceof Creeper) { // Explosions from mobs are not covered by HangingBreakByEntity
if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) { if (hanging instanceof Painting && wcfg.blockEntityPaintingDestroy
event.setCancelled(true); && event.getCause() == RemoveCause.EXPLOSION) {
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); event.setCancelled(true);
} else if (hanging instanceof ItemFrame } else if (hanging instanceof ItemFrame && wcfg.blockEntityItemFrameDestroy
&& (wcfg.blockEntityItemFrameDestroy && event.getCause() == RemoveCause.EXPLOSION) {
|| (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, hanging.getLocation())))) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -181,7 +189,7 @@ public void onEntityInteract(PlayerInteractEntityEvent event) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (entity instanceof ItemFrame if (entity instanceof ItemFrame
&& ((!plugin.getGlobalRegionManager().allows( && ((!plugin.getGlobalRegionManager().allows(
DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, entity.getLocation())))) { DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, entity.getLocation())))) {