diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-31 01:34:23 +0000 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-31 01:34:23 +0000 |
commit | 000d2a300f3928fde7b6ce6d5261e6e1a873de60 (patch) | |
tree | 1796aba9764268fb3d22505077f0e692d679163d /src | |
parent | c6d4cbda5dfdd2629004b69c51e19326dd2dd6d0 (diff) | |
download | bukkit-000d2a300f3928fde7b6ce6d5261e6e1a873de60.tar bukkit-000d2a300f3928fde7b6ce6d5261e6e1a873de60.tar.gz bukkit-000d2a300f3928fde7b6ce6d5261e6e1a873de60.tar.lz bukkit-000d2a300f3928fde7b6ce6d5261e6e1a873de60.tar.xz bukkit-000d2a300f3928fde7b6ce6d5261e6e1a873de60.zip |
Added PLAYER_ITEM_HELD event
Diffstat (limited to 'src')
4 files changed, 56 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index 3bb78acd..3eca4cdf 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -207,6 +207,13 @@ public abstract class Event { PLAYER_TELEPORT (Category.PLAYER), /** + * Called when a player changes their held item + * + * @see org.bukkit.event.player.PlayerItemHeldEvent + */ + PLAYER_ITEM_HELD (Category.PLAYER), + + /** * BLOCK EVENTS */ diff --git a/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java b/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java new file mode 100644 index 00000000..3970428f --- /dev/null +++ b/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java @@ -0,0 +1,36 @@ + +package org.bukkit.event.player; + +import org.bukkit.entity.Player; + +/** + * Fired when a player changes their currently held item + */ +public class PlayerItemHeldEvent extends PlayerEvent { + private int previous; + private int current; + + public PlayerItemHeldEvent(final Type type, final Player player, final int previous, final int current) { + super(type, player); + this.previous = previous; + this.current = current; + } + + /** + * Gets the previous held slot index + * + * @return Previous slot index + */ + public int getPreviousSlot() { + return previous; + } + + /** + * Gets the new held slot index + * + * @return New slot index + */ + public int getNewSlot() { + return current; + } +} diff --git a/src/main/java/org/bukkit/event/player/PlayerListener.java b/src/main/java/org/bukkit/event/player/PlayerListener.java index 79bc30ca..3ab8d037 100644 --- a/src/main/java/org/bukkit/event/player/PlayerListener.java +++ b/src/main/java/org/bukkit/event/player/PlayerListener.java @@ -97,4 +97,12 @@ public class PlayerListener implements Listener { */ public void onInventoryOpen(PlayerInventoryEvent event) { } + + /** + * Called when a player changes their held item + * + * @param event Relevant event details + */ + public void onItemHeldChange(PlayerItemHeldEvent event) { + } } diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index e34b92a0..5d959978 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -173,6 +173,11 @@ public final class JavaPluginLoader implements PluginLoader { ((PlayerListener)listener).onInventoryOpen( (PlayerInventoryEvent)event ); } }; + case PLAYER_ITEM_HELD: + return new EventExecutor() { public void execute( Listener listener, Event event ) { + ((PlayerListener)listener).onItemHeldChange( (PlayerItemHeldEvent)event ); + } + }; // Block Events case BLOCK_PHYSICS: |