From 6c97e04c7c26b9cebdc84b921a61ddbcf1f7c0a3 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 22 Aug 2014 13:45:55 -0700 Subject: [PATCH] Use event abstraction for blacklist item pickup. --- .../bukkit/listener/BlacklistListener.java | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java index 741dc80a..6ffec1e0 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java @@ -45,10 +45,8 @@ import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockDispenseEvent; import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; import static com.sk89q.worldguard.bukkit.BukkitUtil.createTarget; @@ -192,6 +190,16 @@ public void onDestroyEntity(DestroyEntityEvent event) { return; } + if (target instanceof Item) { + Item item = (Item) target; + if (!wcfg.getBlacklist().check( + new ItemAcquireBlacklistEvent(localPlayer, + toVector(target.getLocation()), createTarget(item.getItemStack())), false, true)) { + event.setCancelled(true); + return; + } + } + Material material = Materials.getRelatedMaterial(target.getType()); if (material != null) { // Not really a block but we only have one on-break blacklist event @@ -239,22 +247,6 @@ public void onPlayerDropItem(PlayerDropItemEvent event) { } } - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onPlayerPickupItem(PlayerPickupItemEvent event) { - ConfigurationManager cfg = getPlugin().getGlobalStateManager(); - WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld()); - - if (wcfg.getBlacklist() != null) { - Item ci = event.getItem(); - - if (!wcfg.getBlacklist().check( - new ItemAcquireBlacklistEvent(getPlugin().wrapPlayer(event.getPlayer()), - toVector(ci.getLocation()), createTarget(ci.getItemStack())), false, true)) { - event.setCancelled(true); - } - } - } - @EventHandler(ignoreCancelled = true) public void onBlockDispense(BlockDispenseEvent event) { ConfigurationManager cfg = getPlugin().getGlobalStateManager();