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
    • getItemInMainHand

      @NotNull public @NotNull ItemStack getItemInMainHand()
      Description copied from interface: EquipmentHandler
      Gets the ItemStack in main hand.
      Specified by:
      getItemInMainHand in interface EquipmentHandler
      Returns:
      the ItemStack in main hand
    • setItemInMainHand

      public void setItemInMainHand(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the main hand ItemStack.
      Specified by:
      setItemInMainHand in interface EquipmentHandler
      Parameters:
      itemStack - the main hand ItemStack
    • getItemInOffHand

      @NotNull public @NotNull ItemStack getItemInOffHand()
      Description copied from interface: EquipmentHandler
      Gets the ItemStack in off hand.
      Specified by:
      getItemInOffHand in interface EquipmentHandler
      Returns:
      the item in off hand
    • setItemInOffHand

      public void setItemInOffHand(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the off hand ItemStack.
      Specified by:
      setItemInOffHand in interface EquipmentHandler
      Parameters:
      itemStack - the off hand ItemStack
    • getHelmet

      @NotNull public @NotNull ItemStack getHelmet()
      Description copied from interface: EquipmentHandler
      Gets the helmet.
      Specified by:
      getHelmet in interface EquipmentHandler
      Returns:
      the helmet
    • setHelmet

      public void setHelmet(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the helmet.
      Specified by:
      setHelmet in interface EquipmentHandler
      Parameters:
      itemStack - the helmet
    • getChestplate

      @NotNull public @NotNull ItemStack getChestplate()
      Description copied from interface: EquipmentHandler
      Gets the chestplate.
      Specified by:
      getChestplate in interface EquipmentHandler
      Returns:
      the chestplate
    • setChestplate

      public void setChestplate(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the chestplate.
      Specified by:
      setChestplate in interface EquipmentHandler
      Parameters:
      itemStack - the chestplate
    • getLeggings

      @NotNull public @NotNull ItemStack getLeggings()
      Description copied from interface: EquipmentHandler
      Gets the leggings.
      Specified by:
      getLeggings in interface EquipmentHandler
      Returns:
      the leggings
    • setLeggings

      public void setLeggings(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the leggings.
      Specified by:
      setLeggings in interface EquipmentHandler
      Parameters:
      itemStack - the leggings
    • getBoots

      @NotNull public @NotNull ItemStack getBoots()
      Description copied from interface: EquipmentHandler
      Gets the boots.
      Specified by:
      getBoots in interface EquipmentHandler
      Returns:
      the boots
    • setBoots

      public void setBoots(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the boots.
      Specified by:
      setBoots in interface EquipmentHandler
      Parameters:
      itemStack - the boots
    • 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, int button)
      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
      button - the primary mouse or secondary mouse button
      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