Added PLAYER_ITEM_HELD event

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-01-31 01:34:23 +00:00
parent 7d5f8c95d4
commit 497ac626bf
4 changed files with 56 additions and 0 deletions

View File

@ -206,6 +206,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
*/

View File

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

View File

@ -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) {
}
}

View File

@ -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: