Interface InventoryContents

All Known Implementing Classes:
InventoryContents.Impl

public interface InventoryContents

Represents the content of an inventory.

This contains several methods which let you get and modify the content of the inventory.

For example, you can get the item at a given slot by using get(SlotPos). You can also fill an entire column with the use of the method fillColumn(int, ClickableItem).

  • Method Details

    • inventory

      SmartInventory inventory()
      Gets the inventory linked to this InventoryContents.
      Cannot be null.
      Returns:
      the inventory
    • pagination

      Pagination pagination()
      Gets the pagination system linked to this InventoryContents.
      Cannot be null.
      Returns:
      the pagination
    • iterator

      Optional<SlotIterator> iterator(String id)
      Gets a previously registered iterator named with the given id.
      If no iterator is found, this will return Optional.empty().
      Parameters:
      id - the id of the iterator
      Returns:
      the found iterator, if there is one
    • newIterator

      SlotIterator newIterator(String id, SlotIterator.Type type, int startRow, int startColumn)
      Creates and registers an iterator using a given id.

      You can retrieve the iterator at any time using the iterator(String) method.

      Parameters:
      id - the id of the iterator
      type - the type of the iterator
      startRow - the starting row of the iterator
      startColumn - the starting column of the iterator
      Returns:
      the newly created iterator
    • newIterator

      SlotIterator newIterator(SlotIterator.Type type, int startRow, int startColumn)
      Creates and returns an iterator.

      This does NOT registers the iterator, thus iterator(String) will not be able to return the iterators created with this method.

      Parameters:
      type - the type of the iterator
      startRow - the starting row of the iterator
      startColumn - the starting column of the iterator
      Returns:
      the newly created iterator
    • newIterator

      SlotIterator newIterator(String id, SlotIterator.Type type, SlotPos startPos)
    • newIterator

      SlotIterator newIterator(SlotIterator.Type type, SlotPos startPos)
    • all

      ClickableItem[][] all()
      Returns a 2D array of ClickableItems containing all the items of the inventory. The ClickableItems can be null when there is no item in the corresponding slot.
      Returns:
      the items of the inventory
    • slots

      List<SlotPos> slots()
      Returns a list of all the slots in the inventory.
      Returns:
      the inventory slots
    • firstEmpty

      Optional<SlotPos> firstEmpty()
      Returns the position of the first empty slot in the inventory, or Optional.empty() if there is no free slot.
      Returns:
      the first empty slot, if there is one
    • get

      Optional<ClickableItem> get(int index)
      Returns the item in the inventory at the given slot index, or Optional.empty() if the slot is empty or if the index is out of bounds.
      Parameters:
      index - the slot index
      Returns:
      the found item, if there is one
    • get

      Optional<ClickableItem> get(int row, int column)
      Same as get(int), but with a row and a column instead of the index.
      See Also:
    • get

      Same as get(int), but with a SlotPos instead of the index.
      See Also:
    • applyRect

      InventoryContents applyRect(int fromRow, int fromColumn, int toRow, int toColumn, BiConsumer<Integer,Integer> apply)
      Apply the consumer on a rectangle inside the inventory using the given positions.
      The created rectangle will have its top-left position at the given from slot index and its bottom-right position at the given to slot index.
      Parameters:
      apply - BiConsumer to accept row and column
      Returns:
      this, for chained calls
    • applyRect

      InventoryContents applyRect(int fromRow, int fromColumn, int toRow, int toColumn, Consumer<ClickableItem> apply)
      Apply the consumer on a rectangle inside the inventory using the given positions. Applies only when the ClickableItem exist in this GUI.
      The created rectangle will have its top-left position at the given from slot index and its bottom-right position at the given to slot index.
      Parameters:
      apply - Consumer to accept each slot
      Returns:
      this, for chained calls
    • set

      InventoryContents set(int index, ClickableItem item)
      Sets the item in the inventory at the given slot index.
      Parameters:
      index - the slot index
      item - the item to set, or null to clear the slot
      Returns:
      this, for chained calls
    • set

      InventoryContents set(int row, int column, ClickableItem item)
      Same as set(int, ClickableItem), but with a row and a column instead of the index.
      See Also:
    • set

      Same as set(int, ClickableItem), but with a SlotPos instead of the index.
      See Also:
    • add

      Adds an item to the first empty slot of the inventory.
      Warning: If there is already a stack of the same item, this will not add the item to the stack, this will always add the item into an empty slot.
      Parameters:
      item - the item to add
      Returns:
      this, for chained calls
    • updateItem

      InventoryContents updateItem(int index, org.bukkit.inventory.ItemStack itemStack)
      Updates the ItemStack of the given ClickableItem at the given slot in this inventory.
      If there's no ClickableItem at the given slot, it creates an empty ClickableItem with the given ItemStack.
      Parameters:
      index - the slot index of the item to update
      itemStack - the new ItemStack
      Returns:
      this, for chained calls
    • updateItem

      InventoryContents updateItem(int row, int column, org.bukkit.inventory.ItemStack itemStack)
      Same as updateItem(int, ItemStack), but with a row and a column instead of the index.
      See Also:
    • updateItem

      InventoryContents updateItem(SlotPos slotPos, org.bukkit.inventory.ItemStack itemStack)
      Same as updateItem(int, ItemStack), but with a SlotPos instead of the index.
      See Also:
    • findItem

      Optional<SlotPos> findItem(org.bukkit.inventory.ItemStack item)
      Looks for the given item and compares them using ItemStack.isSimilar(ItemStack), ignoring the amount.
      This method searches row for row from left to right.
      Parameters:
      item - the item to look for
      Returns:
      an optional containing the position where the item first occurred, or an empty optional
    • findItem

      Optional<SlotPos> findItem(ClickableItem item)
      Looks for the given item and compares them using ItemStack.isSimilar(ItemStack), ignoring the amount.
      This method searches row for row from left to right.
      Parameters:
      item - the clickable item with the item stack to look for
      Returns:
      an optional containing the position where the item first occurred, or an empty optional
    • fill

      Fills the inventory with the given item.
      Parameters:
      item - the item
      Returns:
      this, for chained calls
    • fillRow

      InventoryContents fillRow(int row, ClickableItem item)
      Fills the given inventory row with the given item.
      Parameters:
      row - the row to fill
      item - the item
      Returns:
      this, for chained calls
    • fillColumn

      InventoryContents fillColumn(int column, ClickableItem item)
      Fills the given inventory column with the given item.
      Parameters:
      column - the column to fill
      item - the item
      Returns:
      this, for chained calls
    • fillBorders

      InventoryContents fillBorders(ClickableItem item)
      Fills the inventory borders with the given item.
      Parameters:
      item - the item
      Returns:
      this, for chained calls
    • fillRect

      InventoryContents fillRect(int fromIndex, int toIndex, ClickableItem item)
      Fills a rectangle inside the inventory using the given positions.
      The created rectangle will have its top-left position at the given from slot index and its bottom-right position at the given to slot index.
      Parameters:
      fromIndex - the slot index at the top-left position
      toIndex - the slot index at the bottom-right position
      item - the item
      Returns:
      this, for chained calls
    • fillRect

      InventoryContents fillRect(int fromRow, int fromColumn, int toRow, int toColumn, ClickableItem item)
      Same as fillRect(int, int, ClickableItem), but with SlotPos instead of the indexes.
      See Also:
    • fillRect

      InventoryContents fillRect(SlotPos fromPos, SlotPos toPos, ClickableItem item)
      Same as fillRect(int, int, ClickableItem), but with rows and columns instead of the indexes.
      See Also:
    • fillSquare

      InventoryContents fillSquare(int fromIndex, int toIndex, ClickableItem item)
      Completely fills the provided square with the given ClickableItem.
      Parameters:
      fromIndex - the slot index of the upper left corner
      toIndex - the slot index of the lower right corner
      item - the item
      Returns:
      this, for chained calls
    • fillSquare

      InventoryContents fillSquare(int fromRow, int fromColumn, int toRow, int toColumn, ClickableItem item)
      Completely fills the provided square with the given ClickableItem.
      Parameters:
      fromRow - the row of the upper left corner
      fromColumn - the column of the upper-left corner
      toRow - the row of the lower right corner
      toColumn - the column of the lower right corner
      item - the item
      Returns:
      this, for chained calls
    • fillSquare

      InventoryContents fillSquare(SlotPos fromPos, SlotPos toPos, ClickableItem item)
      Completely fills the provided square with the given ClickableItem.
      Parameters:
      fromPos - the slot position of the upper left corner
      toPos - the slot position of the lower right corner
      item - the item
      Returns:
      this, for chained calls
    • fillPattern

      InventoryContents fillPattern(Pattern<ClickableItem> pattern)
      Fills the inventory with the given Pattern.
      The pattern will start at the first slot.
      Parameters:
      pattern - the filling pattern
      Returns:
      this, for chained calls
      See Also:
    • fillPattern

      InventoryContents fillPattern(Pattern<ClickableItem> pattern, int startIndex)
      Fills the inventory with the given Pattern.
      The pattern will start at the given slot index.
      Parameters:
      pattern - the filling pattern
      startIndex - the start slot index for the filling
      Returns:
      this, for chained calls
      See Also:
    • fillPattern

      InventoryContents fillPattern(Pattern<ClickableItem> pattern, int startRow, int startColumn)
      Fills the inventory with the given Pattern.
      The pattern will start at the given slot position based on the provided row and column.
      Parameters:
      pattern - the filling pattern
      startRow - the start row of the slot for filling
      startColumn - the start column of the slot for filling
      Returns:
      this, for chained calls
      See Also:
    • fillPattern

      InventoryContents fillPattern(Pattern<ClickableItem> pattern, SlotPos startPos)
      Fills the inventory with the given Pattern.
      The pattern will start at the given slot position.
      Parameters:
      pattern - the filling pattern
      startPos - the start position of the slot for filling
      Returns:
      this, for chained calls
      See Also:
    • fillPatternRepeating

      InventoryContents fillPatternRepeating(Pattern<ClickableItem> pattern)
      Fills the inventory with the given Pattern.
      The pattern will start at the first slot and end at the last slot. If the pattern is not big enough, it will wrap around to the other side and repeat the pattern.
      The top-left corner of the specified inventory area is also the top-left corner of the specified pattern.
      For this to work the pattern needs to be created with wrapAround enabled.
      Parameters:
      pattern - the filling pattern
      Returns:
      this, for chained calls
      See Also:
    • fillPatternRepeating

      InventoryContents fillPatternRepeating(Pattern<ClickableItem> pattern, int startIndex, int endIndex)
      Fills the inventory with the given Pattern.
      The pattern will start at the first slot index and end at the second slot index. If the pattern is not big enough, it will wrap around to the other side and repeat the pattern.
      The top-left corner of the specified inventory area is also the top-left corner of the specified pattern.
      If endIndex is a negative value it is set to the bottom-right corner.
      For this to work the pattern needs to be created with wrapAround enabled.
      Parameters:
      pattern - the filling pattern
      startIndex - the start slot index where the pattern should begin
      endIndex - the end slot index where the pattern should end
      Returns:
      this, for chained calls
      See Also:
    • fillPatternRepeating

      InventoryContents fillPatternRepeating(Pattern<ClickableItem> pattern, int startRow, int startColumn, int endRow, int endColumn)
      Fills the inventory with the given Pattern.
      The pattern will start at the given slot position and end at the second slot position. If the pattern is not big enough, it will wrap around to the other side and repeat the pattern.
      The top-left corner of the specified inventory area is also the top-left corner of the specified pattern.
      If endRow is a negative value, endRow is automatically set to the max row size, if endColumn is a negative value, endColumn is automatically set to the max column size.
      For this to work the pattern needs to be created with wrapAround enabled.
      Parameters:
      pattern - the filling pattern
      startRow - the start row of the slot for filling
      startColumn - the start column of the slot for filling
      endRow - the end row of the slot for filling
      endColumn - the end column of the slot for filling
      Returns:
      this, for chained calls
      See Also:
    • fillPatternRepeating

      InventoryContents fillPatternRepeating(Pattern<ClickableItem> pattern, SlotPos startPos, SlotPos endPos)
      Fills the inventory with the given Pattern.
      The pattern will start at the given slot position and end at the second slot position. If the pattern is not big enough, it will wrap around to the other side and repeat the pattern.
      The top-left corner of the specified inventory area is also the top-left corner of the specified pattern.
      If the row of endPos is a negative value, endRow is automatically set to the max row size, if the column of endPos is a negative value, endColumn is automatically set to the max column size.
      For this to work the pattern needs to be created with wrapAround enabled.
      Parameters:
      pattern - the filling pattern
      startPos - the position where the pattern should start
      endPos - the position where the pattern should end
      Returns:
      this, for chained calls
      See Also:
    • property

      <T> T property(String name)
      Gets the value of the property with the given name.
      Type Parameters:
      T - the type of the value
      Parameters:
      name - the property's name
      Returns:
      the property's value
    • property

      <T> T property(String name, T def)
      Gets the value of the property with the given name, or a default value if the property isn't set.
      Type Parameters:
      T - the type of the value
      Parameters:
      name - the property's name
      def - the default value
      Returns:
      the property's value, or the given default value
    • setProperty

      InventoryContents setProperty(String name, Object value)
      Sets the value of the property with the given name.
      This will replace the existing value for the property, if there is one.
      Parameters:
      name - the property's name
      value - the new property's value
      Returns:
      this, for chained calls
    • setEditable

      void setEditable(SlotPos slot, boolean editable)
      Makes a slot editable, which enables the player to put items in and take items out of the inventory in the specified slot.
      Parameters:
      slot - The slot to set editable
      editable - true to make a slot editable, false to make it 'static' again.
    • isEditable

      boolean isEditable(SlotPos slot)
      Returns if a given slot is editable or not.
      Parameters:
      slot - The slot to check
      Returns:
      true if the editable.
      See Also: