Switched water/lava bucket block to use new onItemUse hook.

This commit is contained in:
sk89q 2010-11-28 15:54:29 -08:00
parent 6d39ce7240
commit cf31df35ec
2 changed files with 20 additions and 17 deletions

View File

@ -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");

View File

@ -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;
}