Class GuiItemContainer

java.lang.Object
com.github.stefvanschie.inventoryframework.pane.util.GuiItemContainer

public class GuiItemContainer extends Object
A container for storing a grid of GuiItems.
Since:
0.12.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    GuiItemContainer(@Range(from=0L,to=2147483647L) int length, @Range(from=0L,to=2147483647L) int height)
    Creates a new container with the provided length and height.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(@NotNull GuiItemContainer container, @Range(from=0L,to=2147483647L) int startX, @Range(from=0L,to=2147483647L) int startY)
    Puts all items from the container in this container.
    void
    Clears the items of this container.
    Creates a deep copy of this container.
    excludeRows(@Range(from=0L,to=2147483647L) int from, int end)
    Returns a new container, excluding the range of specified rows.
    @Range(from=0L,to=2147483647L) int
    Gets the height of this container.
    @Nullable GuiItem
    getItem(@Range(from=0L,to=2147483647L) int x, @Range(from=0L,to=2147483647L) int y)
    Gets the item at the specified coordinates, or null if this cell is empty.
    @Range(from=0L,to=2147483647L) int
    Gets the length of this container.
    boolean
    Checks whether this container has at least one item.
    boolean
    hasItem(@Range(from=0L,to=2147483647L) int x, @Range(from=0L,to=2147483647L) int y)
    Checks whether the item at the specified coordinates exists.
    void
    setItem(@NotNull GuiItem guiItem, @Range(from=0L,to=2147483647L) int x, @Range(from=0L,to=2147483647L) int y)
    Adds the specified item in the slot at the specified positions.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GuiItemContainer

      public GuiItemContainer(@Range(from=0L,to=2147483647L) int length, @Range(from=0L,to=2147483647L) int height)
      Creates a new container with the provided length and height. The length and height must both be positive numbers.
      Parameters:
      length - the length of the container
      height - the height of the container
      Since:
      0.12.0
  • Method Details

    • excludeRows

      @NotNull @Contract(value="_, _ -> new", pure=true) public @NotNull GuiItemContainer excludeRows(@Range(from=0L,to=2147483647L) int from, int end)
      Returns a new container, excluding the range of specified rows. The new container will have its size shrunk so only the included rows are present and any items in the excluded rows are discarded. Note that while this does make a new container, it does not make a copy. For example, the items in the new gui component will be the exact same items as in this one and will not be copied. The specified range is 0-indexed: the first row starts at index 0 and the last row ends at height - 1. The range is inclusive on both ends, the row specified at either parameter will also be excluded. When the range specified is invalid - that is, part of the range contains rows that are not included in this container, an IllegalArgumentException will be thrown.
      Parameters:
      from - the starting index of the range
      end - the ending index of the range
      Returns:
      the new, shrunk container
      Since:
      0.12.0
    • copy

      @NotNull @Contract(value="-> new", pure=true) public @NotNull GuiItemContainer copy()
      Creates a deep copy of this container. This means that all internal items will be cloned. The returned container is guaranteed to not reference equals this container.
      Returns:
      the new container
      Since:
      0.12.0
    • hasItem

      @Contract(pure=true) public boolean hasItem()
      Checks whether this container has at least one item. If it does, true is returned; false otherwise.
      Returns:
      true if this has an item, false otherwise
      Since:
      0.12.0
    • setItem

      public void setItem(@NotNull @NotNull GuiItem guiItem, @Range(from=0L,to=2147483647L) int x, @Range(from=0L,to=2147483647L) int y)
      Adds the specified item in the slot at the specified positions. This will override an already set item if it resides in the same position as specified. If the position specified is outside the boundaries set by this container, an IllegalArgumentException will be thrown.
      Parameters:
      guiItem - the item to place in this container
      x - the x coordinate of the item
      y - the y coordinate of the item
      Throws:
      IllegalArgumentException - when the coordinates are out of bounds
      Since:
      0.12.0
    • getItem

      @Nullable @Contract(pure=true) public @Nullable GuiItem getItem(@Range(from=0L,to=2147483647L) int x, @Range(from=0L,to=2147483647L) int y)
      Gets the item at the specified coordinates, or null if this cell is empty. If the specified coordinates are not within this container, an IllegalArgumentException will be thrown.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the item or null
      Throws:
      IllegalArgumentException - when the coordinates are out of bounds
      Since:
      0.12.0
    • clearItems

      public void clearItems()
      Clears the items of this container.
      Since:
      0.12.0
    • hasItem

      @Contract(pure=true) public boolean hasItem(@Range(from=0L,to=2147483647L) int x, @Range(from=0L,to=2147483647L) int y)
      Checks whether the item at the specified coordinates exists. If the specified coordinates are not within this container, an IllegalArgumentException will be thrown.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      true if an item exists at the given coordinates, false otherwise
      Throws:
      IllegalArgumentException - when the coordinates are out of bounds
      Since:
      0.12.0
    • getHeight

      @Contract(pure=true) public @Range(from=0L,to=2147483647L) int getHeight()
      Gets the height of this container.
      Returns:
      the height
      Since:
      0.12.0
    • getLength

      @Contract(pure=true) public @Range(from=0L,to=2147483647L) int getLength()
      Gets the length of this container.
      Returns:
      the length
      Since:
      0.12.0
    • apply

      public void apply(@NotNull @NotNull GuiItemContainer container, @Range(from=0L,to=2147483647L) int startX, @Range(from=0L,to=2147483647L) int startY)
      Puts all items from the container in this container. The items will not be copied, nor will their UUID be applied again. The items will be placed starting at the specified x and y coordinates. Any items that are outside the confines of this container will be ignored. The provided container will not be modified. Any items that were already in this container will be overwritten by the items from the provided container. However, currently existing items will not be overwritten with null.
      Parameters:
      container - the container to obtain items from
      startX - the starting x coordinate
      startY - the starting y coordinate
      Since:
      0.12.0