From 80df9c6aa4c2d99b3981e7a8a0c85d128ada0828 Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 30 Nov 2010 21:54:36 -0800 Subject: [PATCH] Improved blacklist support for the new hooks. --- src/WorldGuard.java | 1 + src/WorldGuardListener.java | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/WorldGuard.java b/src/WorldGuard.java index c7fd16d0..3eccd015 100644 --- a/src/WorldGuard.java +++ b/src/WorldGuard.java @@ -75,6 +75,7 @@ public void initialize() { registerHook("BLOCK_CREATED", PluginListener.Priority.HIGH); registerHook("BLOCK_DESTROYED", PluginListener.Priority.CRITICAL); registerHook("BLOCK_BROKEN", PluginListener.Priority.HIGH); + registerHook("BLOCK_PLACE", PluginListener.Priority.HIGH); registerHook("DISCONNECT", PluginListener.Priority.HIGH); registerHook("ITEM_DROP", PluginListener.Priority.HIGH); if (!registerHook("ITEM_USE", PluginListener.Priority.HIGH)) { diff --git a/src/WorldGuardListener.java b/src/WorldGuardListener.java index 1abec67b..57fcea8c 100644 --- a/src/WorldGuardListener.java +++ b/src/WorldGuardListener.java @@ -598,8 +598,12 @@ public boolean onInventoryChange(Player player) { @Override public boolean onItemUse(Player player, Item item) { if (blacklist != null) { - if (!blacklist.onCreate(item.getItemId(), player)) { - return true; + int itemId = item.getItemId(); + + if (itemId >= 325 && itemId <= 327) { + if (!blacklist.onCreate(itemId, player)) { + return true; + } } } @@ -607,22 +611,25 @@ public boolean onItemUse(Player player, Item item) { } /** - * Called when someone presses right click. If they right clicked with a - * block you can return true to cancel that. You can intercept this to add - * your own right click actions to different item types (see itemInHand) + * Called when someone places a block. Return true to prevent the placement. * * @param player * @param blockPlaced * @param blockClicked * @param itemInHand - * @return false if you want the action to go through + * @return true if you want to undo the block placement */ @Override - public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicked, - int itemInHand) { + public boolean onBlockPlace(Player player, Block blockPlaced, + Block blockClicked, Item itemInHand) { + + int itemId = itemInHand.getItemId(); + if (blacklist != null) { - if (!blacklist.onCreate(itemInHand, player)) { - return true; + if (itemId < 325 || itemId > 327) { + if (!blacklist.onCreate(itemId, player)) { + return true; + } } if (!blacklist.onUse(blockClicked, player)) {