Improved blacklist support for the new hooks.

This commit is contained in:
sk89q 2010-11-30 21:54:36 -08:00
parent 8073089da4
commit 80df9c6aa4
2 changed files with 18 additions and 10 deletions

View File

@ -75,6 +75,7 @@ public void initialize() {
registerHook("BLOCK_CREATED", PluginListener.Priority.HIGH); registerHook("BLOCK_CREATED", PluginListener.Priority.HIGH);
registerHook("BLOCK_DESTROYED", PluginListener.Priority.CRITICAL); registerHook("BLOCK_DESTROYED", PluginListener.Priority.CRITICAL);
registerHook("BLOCK_BROKEN", PluginListener.Priority.HIGH); registerHook("BLOCK_BROKEN", PluginListener.Priority.HIGH);
registerHook("BLOCK_PLACE", PluginListener.Priority.HIGH);
registerHook("DISCONNECT", PluginListener.Priority.HIGH); registerHook("DISCONNECT", PluginListener.Priority.HIGH);
registerHook("ITEM_DROP", PluginListener.Priority.HIGH); registerHook("ITEM_DROP", PluginListener.Priority.HIGH);
if (!registerHook("ITEM_USE", PluginListener.Priority.HIGH)) { if (!registerHook("ITEM_USE", PluginListener.Priority.HIGH)) {

View File

@ -598,32 +598,39 @@ public boolean onInventoryChange(Player player) {
@Override @Override
public boolean onItemUse(Player player, Item item) { public boolean onItemUse(Player player, Item item) {
if (blacklist != null) { if (blacklist != null) {
if (!blacklist.onCreate(item.getItemId(), player)) { int itemId = item.getItemId();
if (itemId >= 325 && itemId <= 327) {
if (!blacklist.onCreate(itemId, player)) {
return true; return true;
} }
} }
}
return false; return false;
} }
/** /**
* Called when someone presses right click. If they right clicked with a * Called when someone places a block. Return true to prevent the placement.
* 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)
* *
* @param player * @param player
* @param blockPlaced * @param blockPlaced
* @param blockClicked * @param blockClicked
* @param itemInHand * @param itemInHand
* @return false if you want the action to go through * @return true if you want to undo the block placement
*/ */
@Override @Override
public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicked, public boolean onBlockPlace(Player player, Block blockPlaced,
int itemInHand) { Block blockClicked, Item itemInHand) {
int itemId = itemInHand.getItemId();
if (blacklist != null) { if (blacklist != null) {
if (!blacklist.onCreate(itemInHand, player)) { if (itemId < 325 || itemId > 327) {
if (!blacklist.onCreate(itemId, player)) {
return true; return true;
} }
}
if (!blacklist.onUse(blockClicked, player)) { if (!blacklist.onUse(blockClicked, player)) {
return true; return true;