Class AbstractInventory

All Implemented Interfaces:
InventoryClickHandler, Taggable, TagReadable, TagWritable
Direct Known Subclasses:
Inventory, PlayerInventory

public abstract sealed class AbstractInventory extends Object implements InventoryClickHandler, Taggable permits Inventory, PlayerInventory
Represents an inventory where items can be modified/retrieved.
  • Field Details

  • Constructor Details

    • AbstractInventory

      protected AbstractInventory(int size)
  • Method Details

    • setItemStack

      public void setItemStack(int slot, @NotNull @NotNull ItemStack itemStack)
      Sets an ItemStack at the specified slot and send relevant update to the viewer(s).
      slot - the slot to set the item
      itemStack - the item to set
    • safeItemInsert

      protected final void safeItemInsert(int slot, @NotNull @NotNull ItemStack itemStack, boolean sendPacket)
      Inserts safely an item into the inventory.

      This will update the slot for all viewers and warn the inventory that the window items packet is not up-to-date.

      slot - the internal slot id
      itemStack - the item to insert (use air instead of null)
      IllegalArgumentException - if the slot slot does not exist
    • safeItemInsert

      protected final void safeItemInsert(int slot, @NotNull @NotNull ItemStack itemStack)
    • UNSAFE_itemInsert

      protected abstract void UNSAFE_itemInsert(int slot, @NotNull @NotNull ItemStack itemStack, boolean sendPacket)
    • processItemStack

      @NotNull public <T> T processItemStack(@NotNull @NotNull ItemStack itemStack, @NotNull @NotNull TransactionType type, @NotNull @NotNull TransactionOption<T> option)
    • processItemStacks

      @NotNull public <T> @NotNull List<@NotNull T> processItemStacks(@NotNull @NotNull List<@NotNull ItemStack> itemStacks, @NotNull @NotNull TransactionType type, @NotNull @NotNull TransactionOption<T> option)
    • addItemStack

      @NotNull public <T> T addItemStack(@NotNull @NotNull ItemStack itemStack, @NotNull @NotNull TransactionOption<T> option)
      Adds an ItemStack to the inventory and sends relevant update to the viewer(s).
      itemStack - the item to add
      option - the transaction option
      true if the item has been successfully added, false otherwise
    • addItemStack

      public boolean addItemStack(@NotNull @NotNull ItemStack itemStack)
    • addItemStacks

      @NotNull public <T> @NotNull List<@NotNull T> addItemStacks(@NotNull @NotNull List<@NotNull ItemStack> itemStacks, @NotNull @NotNull TransactionOption<T> option)
      Adds ItemStacks to the inventory and sends relevant updates to the viewer(s).
      itemStacks - items to add
      option - the transaction option
      the operation results
    • takeItemStack

      @NotNull public <T> T takeItemStack(@NotNull @NotNull ItemStack itemStack, @NotNull @NotNull TransactionOption<T> option)
      Takes an ItemStack from the inventory and sends relevant update to the viewer(s).
      itemStack - the item to take
      true if the item has been successfully fully taken, false otherwise
    • takeItemStacks

      @NotNull public <T> @NotNull List<@NotNull T> takeItemStacks(@NotNull @NotNull List<@NotNull ItemStack> itemStacks, @NotNull @NotNull TransactionOption<T> option)
      Takes ItemStacks from the inventory and sends relevant updates to the viewer(s).
      itemStacks - items to take
      the operation results
    • replaceItemStack

      public void replaceItemStack(int slot, @NotNull @NotNull UnaryOperator<@NotNull ItemStack> operator)
    • clear

      public void clear()
      Clears the inventory and send relevant update to the viewer(s).
    • update

      public abstract void update()
    • getItemStack

      @NotNull public @NotNull ItemStack getItemStack(int slot)
      Gets the ItemStack at the specified slot.
      slot - the slot to check
      the item in the slot slot
    • getItemStacks

      @NotNull public @NotNull ItemStack[] getItemStacks()
      Gets all the ItemStack in the inventory.

      Be aware that the returned array does not need to be the original one, meaning that modifying it directly may not work.

      an array containing all the inventory's items
    • getSize

      public int getSize()
      Gets the size of the inventory.
      the inventory's size
    • getInnerSize

      public int getInnerSize()
      Gets the size of the "inner inventory" (which includes only "usable" slots).
      inner inventory's size
    • getInventoryConditions

      @NotNull public @NotNull List<@NotNull InventoryCondition> getInventoryConditions()
      Gets all the InventoryCondition of this inventory.
      a modifiable List containing all the inventory conditions
    • addInventoryCondition

      public void addInventoryCondition(@NotNull @NotNull InventoryCondition inventoryCondition)
      Adds a new InventoryCondition to this inventory.
      inventoryCondition - the inventory condition to add
    • copyContents

      public void copyContents(@NotNull @NotNull ItemStack[] itemStacks)
      Places all the items of itemStacks into the internal array.
      itemStacks - the array to copy the content from
      IllegalArgumentException - if the size of the array is not equal to getSize()
      NullPointerException - if itemStacks contains one null element or more
    • tagHandler

      @NotNull public @NotNull TagHandler tagHandler()
      Specified by:
      tagHandler in interface Taggable