Class GuiItemContainer
java.lang.Object
com.github.stefvanschie.inventoryframework.pane.util.GuiItemContainer
-
Constructor Summary
ConstructorsConstructorDescriptionGuiItemContainer(@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 TypeMethodDescriptionvoidapply(@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.voidClears the items of this container.@NotNull GuiItemContainercopy()Creates a deep copy of this container.@NotNull GuiItemContainerexcludeRows(@Range(from=0L,to=2147483647L) int from, int end) Returns a new container, excluding the range of specified rows.@Range(from=0L,to=2147483647L) intGets the height of this container.@Nullable GuiItemgetItem(@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) intGets the length of this container.booleanhasItem()Checks whether this container has at least one item.booleanhasItem(@Range(from=0L,to=2147483647L) int x, @Range(from=0L,to=2147483647L) int y) Checks whether the item at the specified coordinates exists.voidsetItem(@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.
-
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 containerheight- 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, anIllegalArgumentExceptionwill be thrown.- Parameters:
from- the starting index of the rangeend- the ending index of the range- Returns:
- the new, shrunk container
- Since:
- 0.12.0
-
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, anIllegalArgumentExceptionwill be thrown.- Parameters:
guiItem- the item to place in this containerx- the x coordinate of the itemy- 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, anIllegalArgumentExceptionwill be thrown.- Parameters:
x- the x coordinatey- 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, anIllegalArgumentExceptionwill be thrown.- Parameters:
x- the x coordinatey- 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 fromstartX- the starting x coordinatestartY- the starting y coordinate- Since:
- 0.12.0
-