From d18bdf14e93af640785277582b0f5f50136b3756 Mon Sep 17 00:00:00 2001 From: Patrick Seidel Date: Thu, 27 Dec 2012 17:08:09 -0500 Subject: Add ability to change player item in hand. Adds BUKKIT-3318 --- .../java/org/bukkit/event/player/PlayerItemHeldEvent.java | 12 +++++++++++- src/main/java/org/bukkit/inventory/PlayerInventory.java | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java b/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java index afa374bd..f0d055a0 100644 --- a/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java @@ -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; diff --git a/src/main/java/org/bukkit/inventory/PlayerInventory.java b/src/main/java/org/bukkit/inventory/PlayerInventory.java index 6931ccf9..e7000afd 100644 --- a/src/main/java/org/bukkit/inventory/PlayerInventory.java +++ b/src/main/java/org/bukkit/inventory/PlayerInventory.java @@ -102,6 +102,16 @@ public interface PlayerInventory extends Inventory { */ public int getHeldItemSlot(); + /** + * Set the slot number of the currently held item. + *

+ * 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. -- cgit v1.2.3