001 package org.bukkit.event.player; 002 003 import org.bukkit.entity.Player; 004 import org.bukkit.event.Cancellable; 005 import org.bukkit.event.HandlerList; 006 007 /** 008 * Fired when a player changes their currently held item 009 */ 010 public class PlayerItemHeldEvent extends PlayerEvent implements Cancellable { 011 private static final HandlerList handlers = new HandlerList(); 012 private boolean cancel = false; 013 private final int previous; 014 private final int current; 015 016 public PlayerItemHeldEvent(final Player player, final int previous, final int current) { 017 super(player); 018 this.previous = previous; 019 this.current = current; 020 } 021 022 /** 023 * Gets the previous held slot index 024 * 025 * @return Previous slot index 026 */ 027 public int getPreviousSlot() { 028 return previous; 029 } 030 031 /** 032 * Gets the new held slot index 033 * 034 * @return New slot index 035 */ 036 public int getNewSlot() { 037 return current; 038 } 039 040 public boolean isCancelled() { 041 return cancel; 042 } 043 044 public void setCancelled(boolean cancel) { 045 this.cancel = cancel; 046 } 047 048 @Override 049 public HandlerList getHandlers() { 050 return handlers; 051 } 052 053 public static HandlerList getHandlerList() { 054 return handlers; 055 } 056 }