Class PlayerPickItemEvent

java.lang.Object
org.bukkit.event.Event
org.bukkit.event.player.PlayerEvent
io.papermc.paper.event.player.PlayerPickItemEvent
All Implemented Interfaces:
Cancellable

@NullMarked public class PlayerPickItemEvent extends PlayerEvent implements Cancellable
Event that is fired when a player uses the pick item functionality (middle-clicking a block or entity to get the appropriate item). After the handling of this event, the contents of the source and the target slot will be swapped and the currently selected hotbar slot of the player will be set to the target slot.
  • Constructor Details

    • PlayerPickItemEvent

      @Internal public PlayerPickItemEvent(Player player, int targetSlot, int sourceSlot)
  • Method Details

    • getTargetSlot

      public @org.jetbrains.annotations.Range(from=0L, to=8L) int getTargetSlot()
      Returns the slot the item that is being picked goes into.
      Returns:
      hotbar slot (0-8 inclusive)
    • setTargetSlot

      public void setTargetSlot(@org.jetbrains.annotations.Range(from=0L, to=8L) int targetSlot)
      Changes the slot the item that is being picked goes into.
      Parameters:
      targetSlot - hotbar slot (0-8 inclusive)
    • getSourceSlot

      public @org.jetbrains.annotations.Range(from=-1L, to=35L) int getSourceSlot()
      Returns the slot in which the item that will be put into the players hotbar is located.

      Returns -1 if the item is not in the player's inventory. If this is the case and the player is in creative mode, the item will be spawned in.

      Returns:
      player inventory slot (0-35 inclusive, or -1 if not in the player inventory)
    • setSourceSlot

      public void setSourceSlot(@org.jetbrains.annotations.Range(from=-1L, to=35L) int sourceSlot)
      Change the source slot from which the item that will be put in the players hotbar will be taken.

      If set to -1 and the player is in creative mode, the item will be spawned in.

      Parameters:
      sourceSlot - player inventory slot (0-35 inclusive, or -1 if not in the player inventory)
    • isCancelled

      public boolean isCancelled()
      Description copied from interface: Cancellable
      Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins
      Specified by:
      isCancelled in interface Cancellable
      Returns:
      true if this event is cancelled
    • setCancelled

      public void setCancelled(boolean cancel)
      Description copied from interface: Cancellable
      Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins.
      Specified by:
      setCancelled in interface Cancellable
      Parameters:
      cancel - true if you wish to cancel this event
    • getHandlers

      public HandlerList getHandlers()
      Specified by:
      getHandlers in class Event
    • getHandlerList

      public static HandlerList getHandlerList()