Class PlayerInventory

java.lang.Object
net.minestom.server.inventory.AbstractInventory
net.minestom.server.inventory.PlayerInventory
All Implemented Interfaces:
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

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

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

      public void update(@NotNull @NotNull 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

      @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 item, @NotNull @NotNull ItemStack previous, boolean sendPacket)
      Overrides:
      UNSAFE_itemInsert in class AbstractInventory
    • sendSlotRefresh

      public void sendSlotRefresh(int slot, @NotNull @NotNull ItemStack item, @NotNull @NotNull ItemStack previous)
      Overrides:
      sendSlotRefresh in class AbstractInventory
    • 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
      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
      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)
    • 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
      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
      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
      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)
    • doubleClick

      public boolean doubleClick(@NotNull @NotNull 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