From cf31df35ecdc9a06dc6ee14888d43750c3d10765 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sun, 28 Nov 2010 15:54:29 -0800 Subject: [PATCH] Switched water/lava bucket block to use new onItemUse hook. --- src/WorldGuard.java | 3 +++ src/WorldGuardListener.java | 34 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/WorldGuard.java b/src/WorldGuard.java index fa0569b3..26ae9351 100644 --- a/src/WorldGuard.java +++ b/src/WorldGuard.java @@ -77,6 +77,9 @@ public void initialize() { registerHook("BLOCK_BROKEN", PluginListener.Priority.HIGH); registerHook("DISCONNECT", PluginListener.Priority.HIGH); registerHook("ITEM_DROP", PluginListener.Priority.HIGH); + if (!registerHook("ITEM_USE", PluginListener.Priority.HIGH)) { + missingFeatures.add("denying use of the lava or water buckets"); + } if (!registerHook("ITEM_PICK_UP", PluginListener.Priority.HIGH)) { missingFeatures.add("denying item pickups"); missingFeatures.add("the item durability fix"); diff --git a/src/WorldGuardListener.java b/src/WorldGuardListener.java index 3966b92a..df6ec0c1 100644 --- a/src/WorldGuardListener.java +++ b/src/WorldGuardListener.java @@ -521,6 +521,23 @@ public boolean onInventoryChange(Player player) { return false; } + /** + * Called when a player uses an item (rightclick with item in hand) + * @param player the player + * @param item the item being used (in hand) + * @return true to prevent using the item. + */ + @Override + public boolean onItemUse(Player player, Item item) { + if (blacklist != null) { + if (!blacklist.onCreate(item.getItemId(), player)) { + return true; + } + } + + return false; + } + /** * 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 @@ -537,23 +554,6 @@ public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicke int itemInHand) { if (blacklist != null) { if (!blacklist.onCreate(itemInHand, player)) { - // Water/lava bucket fix - if (itemInHand == 326 || itemInHand == 327) { - final int x = blockPlaced.getX(); - final int y = blockPlaced.getY(); - final int z = blockPlaced.getZ(); - final int existingID = etc.getServer().getBlockIdAt(x, y, z); - - // This is REALLY BAD, but there's no other choice - // at the moment that is as reliable - timer.schedule(new TimerTask() { - public void run() { - try { - etc.getServer().setBlockAt(existingID, x, y, z); - } catch (Throwable t) {} - } - }, 200); // Just in case - } return true; }