Class PlayerInventory

java.lang.Object
net.minestom.server.inventory.AbstractInventory
net.minestom.server.inventory.PlayerInventory
All Implemented Interfaces:
EquipmentHandler, InventoryClickHandler, Taggable, TagReadable, TagWritable

public non-sealed class PlayerInventory extends AbstractInventory implements EquipmentHandler
Represents the inventory of a Player, retrieved with Player.getInventory().
  • Field Details

  • Constructor Details

    • PlayerInventory

      public PlayerInventory(@NotNull @NotNull Player player)
  • Method Details

    • clear

      public void clear()
      Description copied from class: AbstractInventory
      Clears the inventory and send relevant update to the viewer(s).
      Overrides:
      clear in class AbstractInventory
    • getInnerSize

      public int getInnerSize()
      Description copied from class: AbstractInventory
      Gets the size of the "inner inventory" (which includes only "usable" slots).
      Overrides:
      getInnerSize in class AbstractInventory
      Returns:
      inner inventory's size
    • getEquipment

      @NotNull public @NotNull ItemStack getEquipment(@NotNull @NotNull EquipmentSlot slot)
      Description copied from interface: EquipmentHandler
      Gets the equipment in a specific slot.
      Specified by:
      getEquipment in interface EquipmentHandler
      Parameters:
      slot - the equipment to get the item from
      Returns:
      the equipment ItemStack
    • setEquipment

      public void setEquipment(@NotNull @NotNull EquipmentSlot slot, @NotNull @NotNull ItemStack itemStack)
      Specified by:
      setEquipment in interface EquipmentHandler
    • update

      public void update()
      Refreshes the player inventory by sending a WindowItemsPacket containing all. the inventory items
      Specified by:
      update in class AbstractInventory
    • getCursorItem

      @NotNull public @NotNull ItemStack getCursorItem()
      Gets the item in player cursor.
      Returns:
      the cursor item
    • setCursorItem

      public void setCursorItem(@NotNull @NotNull ItemStack cursorItem)
      Changes the player cursor item.
      Parameters:
      cursorItem - the new cursor item
    • UNSAFE_itemInsert

      protected void UNSAFE_itemInsert(int slot, @NotNull @NotNull ItemStack itemStack, boolean sendPacket)
      Specified by:
      UNSAFE_itemInsert in class AbstractInventory
    • sendSlotRefresh

      protected void sendSlotRefresh(short slot, ItemStack itemStack)
      Refreshes an inventory slot.
      Parameters:
      slot - the packet slot, see PlayerInventoryUtils.convertToPacketSlot(int)
      itemStack - the item stack in the slot
    • leftClick

      public boolean leftClick(@NotNull @NotNull Player player, int slot)
      Description copied from interface: InventoryClickHandler
      Called when a Player left click in the inventory. Can also be to drop the cursor item
      Specified by:
      leftClick in interface InventoryClickHandler
      Parameters:
      player - the player who clicked
      slot - the slot number
      Returns:
      true if the click hasn't been cancelled, false otherwise
    • rightClick

      public boolean rightClick(@NotNull @NotNull Player player, int slot)
      Description copied from interface: InventoryClickHandler
      Called when a Player right click in the inventory. Can also be to drop the cursor item
      Specified by:
      rightClick in interface InventoryClickHandler
      Parameters:
      player - the player who clicked
      slot - the slot number
      Returns:
      true if the click hasn't been cancelled, false otherwise
    • middleClick

      public boolean middleClick(@NotNull @NotNull Player player, int slot)
      Specified by:
      middleClick in interface InventoryClickHandler
    • drop

      public boolean drop(@NotNull @NotNull Player player, boolean all, int slot, int button)
      Description copied from interface: InventoryClickHandler
      Called when a Player press the drop button
      Specified by:
      drop in interface InventoryClickHandler
      Parameters:
      player - the player who clicked
      all -
      slot - the slot number
      button - -999 if clicking outside, normal if he is not
      Returns:
      true if the drop hasn't been cancelled, false otherwise
    • shiftClick

      public boolean shiftClick(@NotNull @NotNull Player player, int slot)
      Description copied from interface: InventoryClickHandler
      Called when a Player shift click in the inventory
      Specified by:
      shiftClick in interface InventoryClickHandler
      Parameters:
      player - the player who clicked
      slot - the slot number
      Returns:
      true if the click hasn't been cancelled, false otherwise
    • changeHeld

      public boolean changeHeld(@NotNull @NotNull Player player, int slot, int key)
      Description copied from interface: InventoryClickHandler
      Called when a Player held click in the inventory
      Specified by:
      changeHeld in interface InventoryClickHandler
      Parameters:
      player - the player who clicked
      slot - the slot number
      key - the held slot (0-8) pressed
      Returns:
      true if the click hasn't been cancelled, false otherwise
    • dragging

      public boolean dragging(@NotNull @NotNull Player player, int slot, int button)
      Specified by:
      dragging in interface InventoryClickHandler
    • doubleClick

      public boolean doubleClick(@NotNull @NotNull Player player, int slot)
      Description copied from interface: InventoryClickHandler
      Called when a Player double click in the inventory
      Specified by:
      doubleClick in interface InventoryClickHandler
      Parameters:
      player - the player who clicked
      slot - the slot number
      Returns:
      true if the click hasn't been cancelled, false otherwise