Class GuiComponent
java.lang.Object
com.github.stefvanschie.inventoryframework.gui.GuiComponent
Represents a component within a gui that can hold items. This is always in the shape of a rectangular grid.
- Since:
- 0.8.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final @NotNull List<PositionedPane> A set of all panes in this inventory. -
Constructor Summary
ConstructorsConstructorDescriptionGuiComponent(int length, int height) Creates a new gui component with the specified length and width. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a pane to the current collection of panes.voidclick(@NotNull Gui gui, @NotNull InventoryClickEvent event, int index) Delegates the handling of the specified click event to the panes of this component.@NotNull GuiComponentcopy()Creates a deep copy of this gui component.voiddisplay()This will make each pane in this component render their items in this gui component.voidThis will make each pane in this component render their items in this inventory component.voiddisplay(@NotNull PlayerInventory inventory, int offset) This will make each pane in this component render their items in this gui component.@NotNull GuiComponentexcludeRows(int from, int end) Returns a new gui component, excluding the range of specified rows.intGets the height of this gui component.intGets the length of this gui component.getPanes()Gets a list of panes this gui component contains.@NotNull List<? extends PositionedPane> Gets a list of panes with their positions this gui component contains.booleanhasItem()Checks whether this component has at least one item.voidLoads the provided element's child panes onto this component.voidplaceItems(@NotNull Inventory inventory, int offset) This places the items currently existing in this gui component into the specified inventory.voidplaceItems(@NotNull PlayerInventory inventory, int offset) This places the items currently existing in this gui component into the specified player inventory.
-
Field Details
-
panes
A set of all panes in this inventory. This is guaranteed to be sorted in order of the pane's priorities, from the lowest priority to the highest priority. The order of panes with the same priority is unspecified.
-
-
Constructor Details
-
GuiComponent
public GuiComponent(int length, int height) Creates a new gui component with the specified length and width. If either the length or the width is less than zero, anIllegalArgumentExceptionwill be thrown.- Parameters:
length- the length of the componentheight- the height of the component- Since:
- 0.8.0
-
-
Method Details
-
addPane
-
display
This will make each pane in this component render their items in this inventory component. The panes are displayed according to their priority, with the lowest priority rendering first and the highest priority (note: highest priority, notPane.Priority.HIGHESTpriority) rendering last. The items displayed in this gui component will be put into the specified inventory. The slots will start at the given offset up to this component's size + the offset specified.- Parameters:
inventory- the inventory to place the items inoffset- the offset from which to start counting the slots- Since:
- 0.8.0
- See Also:
-
display
This will make each pane in this component render their items in this gui component. The panes are displayed according to their priority, with the lowest priority rendering first and the highest priority (note: highest priority, notPane.Priority.HIGHESTpriority) rendering last. The items displayed in this gui component will be put into the inventory found inInventoryHolder.getInventory(). The slots will be placed from the top-right to the bottom-left, continuing from left-to-right, top-to-bottom plus the specified offset. This ordering is different from the normal ordering of the indices of aPlayerInventory. See for the normal ordering of aPlayerInventory's slots its documentation.- Parameters:
inventory- the inventory to place the items inoffset- the offset from which to start counting the slots- Since:
- 0.8.0
- See Also:
-
placeItems
This places the items currently existing in this gui component into the specified player inventory. The slots will be placed from the top-right to the bottom-left, continuing from left-to-right, top-to-bottom plus the specified offset. This ordering is different from the normal ordering of the indices of aPlayerInventory. See for the normal ordering of aPlayerInventory's slots its documentation. In contrast todisplay(PlayerInventory, int)this does not render the panes of this component.- Parameters:
inventory- the inventory to place the items inoffset- the offset from which to start counting the slots- Since:
- 0.8.0
- See Also:
-
placeItems
This places the items currently existing in this gui component into the specified inventory. The slots will start at the given offset up to this component's size + the offset specified. In contrast todisplay(Inventory, int)this does not render the panes of this component.- Parameters:
inventory- the inventory to place the items inoffset- the offset from which to start counting the slots- Since:
- 0.8.0
- See Also:
-
click
public void click(@NotNull @NotNull Gui gui, @NotNull @NotNull InventoryClickEvent event, int index) Delegates the handling of the specified click event to the panes of this component. This will callPane.click(Gui, GuiComponent, InventoryClickEvent, Slot)on each pane until the right item has been found.- Parameters:
gui- the gui this inventory component belongs toevent- the event to delegateindex- the slot that was clicked- Since:
- 0.8.0
-
copy
Creates a deep copy of this gui component. This means that all internal items will be cloned and all panes will be copied as per their ownItemStack.clone()andPane.copy()methods. The returned gui component is guaranteed to not reference equals this gui component.- Returns:
- the new gui component
- Since:
- 0.8.0
-
excludeRows
Returns a new gui component, excluding the range of specified rows. The new gui component will have its size shrunk so only the included rows are present and any items in the excluded rows are discarded. All panes will stay present. Note that while this does make a new gui component, it does not make a copy. For example, the panes in the new gui component will be the exact same panes as in this one and will not be copied. This is also true for any retained items. 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 gui component, andIllegalArgumentExceptionwill be thrown.- Parameters:
from- the starting index of the rangeend- the ending index of the range- Returns:
- the new, shrunk gui component
- Since:
- 0.8.0
-
load
public void load(@NotNull @NotNull Object instance, @NotNull @NotNull Element element, @NotNull @NotNull Plugin plugin) Loads the provided element's child panes onto this component. If the element contains any child panes, this will mutate this component.- Parameters:
instance- the instance to apply field and method references onelement- the element to loadplugin- the plugin to load the panes with- Since:
- 0.10.12
-
hasItem
@Contract(pure=true) public boolean hasItem()Checks whether this component has at least one item. If it does, true is returned; false otherwise.- Returns:
- true if this has an item, false otherwise
- Since:
- 0.8.0
-
display
public void display()This will make each pane in this component render their items in this gui component. The panes are displayed according to their priority, with the lowest priority rendering first and the highest priority (note: highest priority, notPane.Priority.HIGHESTpriority) rendering last.- Since:
- 0.8.0
- See Also:
-
getPositionedPanes
Gets a list of panes with their positions this gui component contains. The returned list is unmodifiable. If this gui component currently does not have any panes, an empty list is returned. This list is guaranteed to be sorted according to the panes' priorities. The returned collection is not synchronized and no guarantees should be made as to the safety of concurrently accessing the returned collection. If synchronized behaviour should be allowed, the returned collection must be synchronized externally.- Returns:
- the panes this component has
- Since:
- 0.12.0
-
getPanes
Gets a list of panes this gui component contains. The returned list is modifiable. If this gui component currently does not have any panes, an empty list is returned. This list is guaranteed to be sorted according to the panes' priorities.- Returns:
- the panes this component has
- Since:
- 0.8.0
-
getHeight
@Contract(pure=true) public int getHeight()Gets the height of this gui component.- Returns:
- the height
- Since:
- 0.8.0
-
getLength
@Contract(pure=true) public int getLength()Gets the length of this gui component.- Returns:
- the length
- Since:
- 0.8.0
-