From cdab00450568d5ce9d6b16fde7fbe3f575876673 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sun, 31 Aug 2014 19:30:14 -0700 Subject: [PATCH] Add option to consider use of an item as a block use at the player's feet. Closes WORLDGUARD-3151. --- .../sk89q/worldguard/bukkit/WorldConfiguration.java | 2 ++ .../bukkit/listener/EventAbstractionListener.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java index 48a22a95..3107489b 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -182,6 +182,7 @@ public class WorldConfiguration { public boolean disableObsidianGenerators; public boolean strictEntitySpawn; public TargetMatcherSet allowAllInteract; + public TargetMatcherSet blockUseAtFeet; private Map maxRegionCounts; @@ -346,6 +347,7 @@ private void loadConfiguration() { strictEntitySpawn = getBoolean("event-handling.block-entity-spawns-with-untraceable-cause", false); allowAllInteract = getTargetMatchers("event-handling.interaction-whitelist"); + blockUseAtFeet = getTargetMatchers("event-handling.emit-block-use-at-feet"); itemDurability = getBoolean("protection.item-durability", true); removeInfiniteStacks = getBoolean("protection.remove-infinite-stacks", false); diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index e0f0ce4a..f0304da4 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -392,6 +392,16 @@ public void onPlayerInteract(PlayerInteractEvent event) { event.setUseItemInHand(Result.DENY); } + // Check for items that the administrator has configured to + // emit a "use block here" event where the player is + // standing, which is a hack to protect items that don't + // throw events + if (item != null && getWorldConfig(player.getWorld()).blockUseAtFeet.test(item)) { + if (Events.fireAndTestCancel(new UseBlockEvent(event, cause, player.getLocation().getBlock()))) { + event.setCancelled(true); + } + } + break; } }