Add ability to change player item in hand. Adds BUKKIT-3318

By: Patrick Seidel <psycowithespn1@aim.com>
This commit is contained in:
Bukkit/Spigot 2012-12-27 17:08:09 -05:00
parent d52aad59f3
commit 07bdbf973d
2 changed files with 21 additions and 1 deletions

View file

@ -1,13 +1,15 @@
package org.bukkit.event.player;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
/**
* Fired when a player changes their currently held item
*/
public class PlayerItemHeldEvent extends PlayerEvent {
public class PlayerItemHeldEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private final int previous;
private final int current;
@ -35,6 +37,14 @@ public class PlayerItemHeldEvent extends PlayerEvent {
return current;
}
public boolean isCancelled() {
return cancel;
}
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;

View file

@ -102,6 +102,16 @@ public interface PlayerInventory extends Inventory {
*/
public int getHeldItemSlot();
/**
* Set the slot number of the currently held item.
* <p>
* This validates whether the slot is between 0 and 8 inclusive.
*
* @param slot The new slot number
* @throws IllegalArgumentException Thrown if slot is not between 0 and 8 inclusive
*/
public void setHeldItemSlot(int slot);
/**
* Clears all matching items from the inventory. Setting either value to -1 will skip it's check,
* while setting both to -1 will clear all items in your inventory unconditionally.