Class PlayerInventory

java.lang.Object
net.minestom.server.inventory.AbstractInventory
net.minestom.server.inventory.PlayerInventory
All Implemented Interfaces:
EventHandler<InventoryEvent>, InventoryClickHandler, Taggable, TagReadable, TagWritable, Viewable

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

  • Constructor Details

    • PlayerInventory

      public PlayerInventory()
  • 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
    • getWindowId

      public byte getWindowId()
      Description copied from class: AbstractInventory
      Gets this window id.

      This is the id that the client will send to identify the affected inventory, mostly used by packets.

      Specified by:
      getWindowId in class AbstractInventory
      Returns:
      the window id
    • getEquipment

      public ItemStack getEquipment(EquipmentSlot slot, byte heldSlot)
    • setEquipment

      public void setEquipment(EquipmentSlot slot, byte heldSlot, ItemStack itemStack)
    • update

      public void update(Player player)
      Description copied from class: AbstractInventory
      Refreshes the inventory for a specific viewer.
      Overrides:
      update in class AbstractInventory
      Parameters:
      player - the player to update the inventory for
    • getCursorItem

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

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

      public void setCursorItem(ItemStack cursorItem, boolean sendPacket)
      Changes the player cursor item.
      Parameters:
      cursorItem - the new cursor item
      sendPacket - true to send the update packet to the client, false otherwise
    • UNSAFE_itemInsert

      protected void UNSAFE_itemInsert(int slot, ItemStack item, ItemStack previous, boolean sendPacket)
      Overrides:
      UNSAFE_itemInsert in class AbstractInventory
    • sendSlotRefresh

      public void sendSlotRefresh(int slot, ItemStack item)
      Overrides:
      sendSlotRefresh in class AbstractInventory
    • leftClick

      public boolean leftClick(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
      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(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
      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(Player player, int slot)
    • drop

      public boolean drop(Player player, boolean all, int slot)
      Description copied from interface: InventoryClickHandler
      Called when a Player press the drop button
      Parameters:
      player - the player who clicked
      all -
      slot - the slot number (-999 if clicking outside, i.e. dropping cursor)
      Returns:
      true if the drop hasn't been cancelled, false otherwise
    • shiftClick

      public boolean shiftClick(Player player, int slot, int button)
      Description copied from interface: InventoryClickHandler
      Called when a Player shift click in the inventory
      Parameters:
      player - the player who clicked
      slot - the slot number
      button - the button (same behaviour in vanilla, but can be used for custom behaviour)
      Returns:
      true if the click hasn't been cancelled, false otherwise
    • changeHeld

      public boolean changeHeld(Player player, int slot, int key)
      Description copied from interface: InventoryClickHandler
      Called when a Player held click in the inventory
      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(Player player, List<Integer> slots, int button)
    • doubleClick

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