Package dev.aurelium.slate.inv.content
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).
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionadd(ClickableItem item) Adds an item to the first empty slot of the inventory.ClickableItem[][]all()Returns a 2D array of ClickableItems containing all the items of the inventory.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.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.fill(ClickableItem item) Fills the inventory with the given item.fillBorders(ClickableItem item) Fills the inventory borders with the given item.fillColumn(int column, ClickableItem item) Fills the given inventory column with the given item.fillPattern(Pattern<ClickableItem> pattern) Fills the inventory with the givenPattern.fillPattern(Pattern<ClickableItem> pattern, int startIndex) Fills the inventory with the givenPattern.fillPattern(Pattern<ClickableItem> pattern, int startRow, int startColumn) Fills the inventory with the givenPattern.fillPattern(Pattern<ClickableItem> pattern, SlotPos startPos) Fills the inventory with the givenPattern.fillPatternRepeating(Pattern<ClickableItem> pattern) Fills the inventory with the givenPattern.fillPatternRepeating(Pattern<ClickableItem> pattern, int startIndex, int endIndex) Fills the inventory with the givenPattern.fillPatternRepeating(Pattern<ClickableItem> pattern, int startRow, int startColumn, int endRow, int endColumn) Fills the inventory with the givenPattern.fillPatternRepeating(Pattern<ClickableItem> pattern, SlotPos startPos, SlotPos endPos) Fills the inventory with the givenPattern.fillRect(int fromRow, int fromColumn, int toRow, int toColumn, ClickableItem item) Same asfillRect(int, int, ClickableItem), but withSlotPosinstead of the indexes.fillRect(int fromIndex, int toIndex, ClickableItem item) Fills a rectangle inside the inventory using the given positions.fillRect(SlotPos fromPos, SlotPos toPos, ClickableItem item) Same asfillRect(int, int, ClickableItem), but with rows and columns instead of the indexes.fillRow(int row, ClickableItem item) Fills the given inventory row with the given item.fillSquare(int fromRow, int fromColumn, int toRow, int toColumn, ClickableItem item) Completely fills the provided square with the givenClickableItem.fillSquare(int fromIndex, int toIndex, ClickableItem item) Completely fills the provided square with the givenClickableItem.fillSquare(SlotPos fromPos, SlotPos toPos, ClickableItem item) Completely fills the provided square with the givenClickableItem.findItem(ClickableItem item) Looks for the given item and compares them usingItemStack.isSimilar(ItemStack), ignoring the amount.findItem(org.bukkit.inventory.ItemStack item) Looks for the given item and compares them usingItemStack.isSimilar(ItemStack), ignoring the amount.Returns the position of the first empty slot in the inventory, orOptional.empty()if there is no free slot.get(int index) Returns the item in the inventory at the given slot index, orOptional.empty()if the slot is empty or if the index is out of bounds.get(int row, int column) Same asget(int), but with a row and a column instead of the index.Gets the inventory linked to thisInventoryContents.booleanisEditable(SlotPos slot) Returns if a given slot is editable or not.Gets a previously registered iterator named with the given id.newIterator(SlotIterator.Type type, int startRow, int startColumn) Creates and returns an iterator.newIterator(SlotIterator.Type type, SlotPos startPos) newIterator(String id, SlotIterator.Type type, int startRow, int startColumn) Creates and registers an iterator using a given id.newIterator(String id, SlotIterator.Type type, SlotPos startPos) Gets the pagination system linked to thisInventoryContents.<T> TGets the value of the property with the given name.<T> TGets the value of the property with the given name, or a default value if the property isn't set.set(int row, int column, ClickableItem item) Same asset(int, ClickableItem), but with a row and a column instead of the index.set(int index, ClickableItem item) Sets the item in the inventory at the given slot index.set(SlotPos slotPos, ClickableItem item) Same asset(int, ClickableItem), but with aSlotPosinstead of the index.voidsetEditable(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.setProperty(String name, Object value) Sets the value of the property with the given name.slots()Returns a list of all the slots in the inventory.updateItem(int row, int column, org.bukkit.inventory.ItemStack itemStack) Same asupdateItem(int, ItemStack), but with a row and a column instead of the index.updateItem(int index, org.bukkit.inventory.ItemStack itemStack) Updates theItemStackof the givenClickableItemat the given slot in this inventory.updateItem(SlotPos slotPos, org.bukkit.inventory.ItemStack itemStack) Same asupdateItem(int, ItemStack), but with aSlotPosinstead of the index.
-
Method Details
-
inventory
SmartInventory inventory()- Returns:
- the inventory
-
pagination
Pagination pagination()- Returns:
- the pagination
-
iterator
Gets a previously registered iterator named with the given id.
If no iterator is found, this will returnOptional.empty().- Parameters:
id- the id of the iterator- Returns:
- the found iterator, if there is one
-
newIterator
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 iteratortype- the type of the iteratorstartRow- the starting row of the iteratorstartColumn- the starting column of the iterator- Returns:
- the newly created iterator
-
newIterator
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 iteratorstartRow- the starting row of the iteratorstartColumn- the starting column of the iterator- Returns:
- the newly created iterator
-
newIterator
-
newIterator
-
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
Returns a list of all the slots in the inventory.- Returns:
- the inventory slots
-
firstEmpty
Returns the position of the first empty slot in the inventory, orOptional.empty()if there is no free slot.- Returns:
- the first empty slot, if there is one
-
get
Returns the item in the inventory at the given slot index, orOptional.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
Same asget(int), but with a row and a column instead of the index.- See Also:
-
get
- 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
Sets the item in the inventory at the given slot index.- Parameters:
index- the slot indexitem- the item to set, ornullto clear the slot- Returns:
this, for chained calls
-
set
Same asset(int, ClickableItem), but with a row and a column instead of the index.- See Also:
-
set
Same asset(int, ClickableItem), but with aSlotPosinstead 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
Updates theItemStackof the givenClickableItemat the given slot in this inventory.
If there's noClickableItemat the given slot, it creates an emptyClickableItemwith the givenItemStack.- Parameters:
index- the slot index of the item to updateitemStack- the newItemStack- Returns:
this, for chained calls
-
updateItem
Same asupdateItem(int, ItemStack), but with a row and a column instead of the index.- See Also:
-
updateItem
Same asupdateItem(int, ItemStack), but with aSlotPosinstead of the index.- See Also:
-
findItem
Looks for the given item and compares them usingItemStack.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
Looks for the given item and compares them usingItemStack.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
Fills the given inventory row with the given item.- Parameters:
row- the row to fillitem- the item- Returns:
this, for chained calls
-
fillColumn
Fills the given inventory column with the given item.- Parameters:
column- the column to fillitem- the item- Returns:
this, for chained calls
-
fillBorders
Fills the inventory borders with the given item.- Parameters:
item- the item- Returns:
this, for chained calls
-
fillRect
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 positiontoIndex- the slot index at the bottom-right positionitem- the item- Returns:
this, for chained calls
-
fillRect
InventoryContents fillRect(int fromRow, int fromColumn, int toRow, int toColumn, ClickableItem item) Same asfillRect(int, int, ClickableItem), but withSlotPosinstead of the indexes.- See Also:
-
fillRect
Same asfillRect(int, int, ClickableItem), but with rows and columns instead of the indexes.- See Also:
-
fillSquare
Completely fills the provided square with the givenClickableItem.- Parameters:
fromIndex- the slot index of the upper left cornertoIndex- the slot index of the lower right corneritem- 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 givenClickableItem.- Parameters:
fromRow- the row of the upper left cornerfromColumn- the column of the upper-left cornertoRow- the row of the lower right cornertoColumn- the column of the lower right corneritem- the item- Returns:
this, for chained calls
-
fillSquare
Completely fills the provided square with the givenClickableItem.- Parameters:
fromPos- the slot position of the upper left cornertoPos- the slot position of the lower right corneritem- the item- Returns:
this, for chained calls
-
fillPattern
Fills the inventory with the givenPattern.
The pattern will start at the first slot.- Parameters:
pattern- the filling pattern- Returns:
this, for chained calls- See Also:
-
fillPattern
Fills the inventory with the givenPattern.
The pattern will start at the given slot index.- Parameters:
pattern- the filling patternstartIndex- the start slot index for the filling- Returns:
this, for chained calls- See Also:
-
fillPattern
Fills the inventory with the givenPattern.
The pattern will start at the given slot position based on the provided row and column.- Parameters:
pattern- the filling patternstartRow- the start row of the slot for fillingstartColumn- the start column of the slot for filling- Returns:
this, for chained calls- See Also:
-
fillPattern
Fills the inventory with the givenPattern.
The pattern will start at the given slot position.- Parameters:
pattern- the filling patternstartPos- the start position of the slot for filling- Returns:
this, for chained calls- See Also:
-
fillPatternRepeating
Fills the inventory with the givenPattern.
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 withwrapAroundenabled.- 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 givenPattern.
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.
IfendIndexis a negative value it is set to the bottom-right corner.
For this to work the pattern needs to be created withwrapAroundenabled.- Parameters:
pattern- the filling patternstartIndex- the start slot index where the pattern should beginendIndex- 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 givenPattern.
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.
IfendRowis a negative value, endRow is automatically set to the max row size, ifendColumnis a negative value, endColumn is automatically set to the max column size.
For this to work the pattern needs to be created withwrapAroundenabled.- Parameters:
pattern- the filling patternstartRow- the start row of the slot for fillingstartColumn- the start column of the slot for fillingendRow- the end row of the slot for fillingendColumn- 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 givenPattern.
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 ofendPosis a negative value, endRow is automatically set to the max row size, if the column ofendPosis a negative value, endColumn is automatically set to the max column size.
For this to work the pattern needs to be created withwrapAroundenabled.- Parameters:
pattern- the filling patternstartPos- the position where the pattern should startendPos- the position where the pattern should end- Returns:
this, for chained calls- See Also:
-
property
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
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 namedef- the default value- Returns:
- the property's value, or the given default value
-
setProperty
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 namevalue- the new property's value- Returns:
this, for chained calls
-
setEditable
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 editableeditable-trueto make a slot editable,falseto make it 'static' again.
-
isEditable
Returns if a given slot is editable or not.- Parameters:
slot- The slot to check- Returns:
trueif the editable.- See Also:
-