From e9361022d22c8575d8ca3a38f65272b8bae48bcc Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 2 Nov 2012 13:41:53 -0700 Subject: [PATCH] Protected against using (right-clicking) paintings and item frames. --- .../bukkit/WorldGuardHangingListener.java | 29 +++++++++++++++++++ .../bukkit/WorldGuardPaintingListener.java | 27 ++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java index 2c6dc2b0..7ccebe48 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java @@ -25,6 +25,7 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Creeper; +import org.bukkit.entity.Entity; import org.bukkit.entity.Hanging; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Painting; @@ -35,6 +36,7 @@ import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; import com.sk89q.worldedit.blocks.ItemID; import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent; @@ -164,4 +166,31 @@ public void onHangingPlace(HangingPlaceEvent event) { } } } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onEntityInteract(PlayerInteractEntityEvent event) { + Player player = event.getPlayer(); + Entity entity = event.getRightClicked(); + + ConfigurationManager cfg = plugin.getGlobalStateManager(); + WorldConfiguration wcfg = cfg.get(entity.getWorld()); + + if (wcfg.useRegions && (entity instanceof ItemFrame || entity instanceof Painting)) { + if (!plugin.getGlobalRegionManager().canBuild(player, entity.getLocation())) { + player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); + event.setCancelled(true); + return; + } + + if (entity instanceof ItemFrame + && ((!plugin.getGlobalRegionManager().allows( + DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, entity.getLocation())))) { + event.setCancelled(true); + } else if (entity instanceof Painting + && ((!plugin.getGlobalRegionManager().allows( + DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) { + event.setCancelled(true); + } + } + } } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPaintingListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPaintingListener.java index d8c3aba7..00402903 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPaintingListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPaintingListener.java @@ -22,9 +22,11 @@ import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector; import org.bukkit.ChatColor; +import org.bukkit.Warning; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Creeper; +import org.bukkit.entity.Entity; import org.bukkit.entity.Painting; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -33,12 +35,12 @@ import org.bukkit.event.painting.PaintingBreakByEntityEvent; import org.bukkit.event.painting.PaintingBreakEvent; import org.bukkit.event.painting.PaintingPlaceEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; import com.sk89q.worldedit.blocks.ItemID; import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent; import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; import com.sk89q.worldguard.protection.flags.DefaultFlag; -import org.bukkit.Warning; /** * Listener for painting related events. @@ -146,4 +148,27 @@ public void onPaintingPlace(PaintingPlaceEvent event) { } } } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onEntityInteract(PlayerInteractEntityEvent event) { + Player player = event.getPlayer(); + Entity entity = event.getRightClicked(); + + ConfigurationManager cfg = plugin.getGlobalStateManager(); + WorldConfiguration wcfg = cfg.get(entity.getWorld()); + + if (wcfg.useRegions && entity instanceof Painting) { + if (!plugin.getGlobalRegionManager().canBuild(player, entity.getLocation())) { + player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); + event.setCancelled(true); + return; + } + + if (entity instanceof Painting + && ((!plugin.getGlobalRegionManager().allows( + DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) { + event.setCancelled(true); + } + } + } }