Class Inventory
- Direct Known Subclasses:
CompositeInventory
,ObscuredInventory
,ReferencingInventory
,VirtualInventory
Guis
.
Provides several utility methods to easily add and remove items from the inventory, as well as an advanced event system allowing to listen for and affect changes in the inventory.
General contracts of this class and all of its implementations are:
-
There are no
ItemStacks
of typeMaterial.AIR
orItemStack.getAmount()
== 0.
EmptyItemStacks
are represented bynull
. -
Unless otherwise specified, all methods will return a clone of the actual backing
ItemStack
.
Changes to returnedItemStacks
will never affect theInventory
. -
Unless otherwise specified, all methods accepting
ItemStacks
will always clone them before putting them in the backing array / inventory.
Changes to the passedItemStacks
after calling a method will never affect theInventory
.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
addItem
(@Nullable UpdateReason updateReason, @NotNull org.bukkit.inventory.ItemStack itemStack) Adds anItemStack
to theInventory
.int
addItemAmount
(@Nullable UpdateReason updateReason, int slot, int amount) Adds a specific amount to anItemStack
on a slot while respecting the maximum allowed stack size on that slot.void
addWindow
(AbstractWindow window) Adds anAbstractWindow
to the set ofAbstractWindows
, telling theInventory
that its contents are now being displayed in thatAbstractWindow
.void
callPostUpdateEvent
(@Nullable UpdateReason updateReason, int slot, @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable org.bukkit.inventory.ItemStack newItemStack) Creates anItemPostUpdateEvent
and calls thepostUpdateHandler
to handle it.callPreUpdateEvent
(@Nullable UpdateReason updateReason, int slot, @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable org.bukkit.inventory.ItemStack newItemStack) Creates anItemPreUpdateEvent
and calls thepreUpdateHandler
to handle it.boolean
boolean
canHold
(@NotNull org.bukkit.inventory.ItemStack first, @NotNull org.bukkit.inventory.ItemStack @NotNull ... rest) int
collectSimilar
(@Nullable UpdateReason updateReason, @NotNull org.bukkit.inventory.ItemStack itemStack) Finds allItemStack
s similar to the providedItemStack
and removes them from their slot until the amount of the givenItemStack
reaches its maximum stack size.int
collectSimilar
(@Nullable UpdateReason updateReason, @NotNull org.bukkit.inventory.ItemStack template, int baseAmount) Finds allItemStack
s similar to the providedItemStack
and removes them from their slot until the maximum stack size of theMaterial
is reached.boolean
boolean
containsSimilar
(org.bukkit.inventory.ItemStack itemStack) int
int
countSimilar
(org.bukkit.inventory.ItemStack itemStack) boolean
forceSetItem
(@Nullable UpdateReason updateReason, int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStack
on a specific slot to that one, regardless of what was previously on that slot.int
Gets the priority for click actions in aGui
, such as shift clicking or cursor collection with multipleVirtualInventories
.abstract @Nullable org.bukkit.inventory.ItemStack
getItem
(int slot) Gets a clone of theItemStack
on that slot.int
getItemAmount
(int slot) Gets theItemStack amount
of theItemStack
on the given slot.abstract @Nullable org.bukkit.inventory.ItemStack @NotNull []
getItems()
Gets a copy of the contents of thisInventory
.abstract int
getMaxSlotStackSize
(int slot) Gets the maximum stack size for a specific slot while ignoring max stack size of theItemStack
on it.int
getMaxSlotStackSize
(int slot, int alternative) Gets the maximum stack size for a specific slot while ignoring theItemStack
on it.int
getMaxSlotStackSize
(int slot, @Nullable org.bukkit.inventory.ItemStack alternativeFrom) Gets the maximum stack size for a specific slot while ignoring theItemStack
on it.int
getMaxStackSize
(int slot) Gets the maximum stack size for a specific slot.int
getMaxStackSize
(int slot, int alternative) Gets the maximum stack size for a specific slot.int
getMaxStackSize
(int slot, @Nullable org.bukkit.inventory.ItemStack alternativeFrom) Gets the maximum stack size for a specific slot.abstract int @NotNull []
Gets the array of max stack sizes for thisInventory
.@Nullable Consumer
<@NotNull ItemPostUpdateEvent> Gets the configured post update handler.@Nullable Consumer
<@NotNull ItemPreUpdateEvent> Gets the configured pre update handler.abstract int
getSize()
Gets the size of thisInventory
.abstract @Nullable org.bukkit.inventory.ItemStack
getUnsafeItem
(int slot) Gets theItemStack
on that slot.abstract @Nullable org.bukkit.inventory.ItemStack @NotNull []
Gets theItemStacks
thisInventory
contains.boolean
Checks whether thisInventory
has at least one empty slot.boolean
Whether thisInventory
has any event handlers.boolean
hasItem
(int slot) Checks if there is anItemStack
on that slot.boolean
isEmpty()
Checks if there are noItemStacks
in thisInventory
.boolean
isFull()
Checks if all slots have anItemStack
with their max stack size on them.boolean
isSynced
(int slot, org.bukkit.inventory.ItemStack assumedStack) Checks if theItemStack
on that slot is the same as the assumedItemStack
provided as parameter.boolean
modifyItem
(@Nullable UpdateReason updateReason, int slot, @NotNull Consumer<@Nullable org.bukkit.inventory.ItemStack> modifier) Changes theItemStack
on a specific slot based on the currentItemStack
on that slot, using a modifier consumer.void
int
putItem
(@Nullable UpdateReason updateReason, int slot, @NotNull org.bukkit.inventory.ItemStack itemStack) Adds anItemStack
on a specific slot and returns the amount of items that did not fit on that slot.int
removeFirst
(@Nullable UpdateReason updateReason, int amount, @NotNull Predicate<@NotNull org.bukkit.inventory.ItemStack> predicate) Removes the first nItemStacks
matching the givenPredicate
.int
removeFirstSimilar
(@Nullable UpdateReason updateReason, int amount, @NotNull org.bukkit.inventory.ItemStack itemStack) Removes the first nItemStacks
that are similar to the specifiedItemStack
.int
removeIf
(@Nullable UpdateReason updateReason, @NotNull Predicate<@NotNull org.bukkit.inventory.ItemStack> predicate) Removes allItemStacks
matching the givenPredicate
.int
removeSimilar
(@Nullable UpdateReason updateReason, @NotNull org.bukkit.inventory.ItemStack itemStack) Removes allItemStacks
that are similar to the specifiedItemStack
.void
removeWindow
(AbstractWindow window) Removes anAbstractWindow
from the set ofAbstractWindows
, telling theInventory
that its contents are no longer being displayed in thatAbstractWindow
.boolean
replaceItem
(@Nullable UpdateReason updateReason, int slot, @NotNull Function<@Nullable org.bukkit.inventory.ItemStack, @Nullable org.bukkit.inventory.ItemStack> function) Replaces theItemStack
on a specific slot based on the currentItemStack
on that slot, using a replace function.protected abstract void
setCloneBackingItem
(int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Clones the givenItemStack
and sets in the backing array of thisInventory
.protected abstract void
setDirectBackingItem
(int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Sets theItemStack
in the backing array of thisInventory
without explicitly cloning it.void
setGuiPriority
(int guiPriority) Sets the priority for click actions in aGui
, such as shift-clicking or cursor collection with multipleVirtualInventories
.boolean
setItem
(@Nullable UpdateReason updateReason, int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStack
on a specific slot to the given one, regardless of what previously was on that slot.int
setItemAmount
(@Nullable UpdateReason updateReason, int slot, int amount) Sets the amount of anItemStack
on a slot to the given value while respecting the max allowed stack size on that slot.void
setItemSilently
(int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStack
on a specific slot to that one, regardless of what was previously on that slot.void
setPostUpdateHandler
(@Nullable Consumer<@NotNull ItemPostUpdateEvent> inventoryUpdatedHandler) Sets a handler which is called every time after something has been updated in theInventory
.void
setPreUpdateHandler
(@Nullable Consumer<@NotNull ItemPreUpdateEvent> preUpdateHandler) Sets a handler which is called every time something gets updated in theInventory
.int[]
simulateAdd
(@NotNull List<@NotNull org.bukkit.inventory.ItemStack> itemStacks) Simulates addingItemStack
s to thisInventory
and returns the amount ofItemStack
s that did not fit.int[]
simulateAdd
(@NotNull org.bukkit.inventory.ItemStack first, @NotNull org.bukkit.inventory.ItemStack @NotNull ... rest) Simulates addingItemStack
s to thisInventory
and returns the amount ofItemStack
s that did not fit.int[]
simulateMultiAdd
(@NotNull List<@NotNull org.bukkit.inventory.ItemStack> itemStacks) Simulates adding multipleItemStack
s to thisInventory
and returns the amount ofItemStack
s that did not fit.int
simulateSingleAdd
(@NotNull org.bukkit.inventory.ItemStack itemStack) Returns the amount of items that wouldn't fit in the inventory when added.
-
Constructor Details
-
Inventory
public Inventory()
-
-
Method Details
-
getSize
public abstract int getSize()Gets the size of thisInventory
.- Returns:
- How many slots this
Inventory
has.
-
getMaxStackSizes
public abstract int @NotNull [] getMaxStackSizes()Gets the array of max stack sizes for thisInventory
.- Returns:
- The array defining the max stack sizes for this
Inventory
-
getMaxSlotStackSize
public abstract int getMaxSlotStackSize(int slot) Gets the maximum stack size for a specific slot while ignoring max stack size of theItemStack
on it.- Parameters:
slot
- The slot- Returns:
- The maximum stack size on that slo
-
getItems
@Nullable public abstract @Nullable org.bukkit.inventory.ItemStack @NotNull [] getItems()Gets a copy of the contents of thisInventory
.It is guaranteed that this method will never return an air / empty item stack. Those are always represented by null.
- Returns:
- A deep copy of the
ItemStacks
thisInventory
contains.
-
getUnsafeItems
@Nullable public abstract @Nullable org.bukkit.inventory.ItemStack @NotNull [] getUnsafeItems()Gets theItemStacks
thisInventory
contains. Depending on the implementation, this method may return a copy, a deep copy, or the actual backing item stack array. Modifying the returned array might or might not reflect in thisInventory
.It is guaranteed that this method will never return an air / empty item stack. Those are always represented by null.
- Returns:
- The
ItemStacks
thisInventory
contains.
-
getItem
@Nullable public abstract @Nullable org.bukkit.inventory.ItemStack getItem(int slot) Gets a clone of theItemStack
on that slot.It is guaranteed that this method will never return an air / empty item stack. Those are always represented by null.
- Parameters:
slot
- The slot- Returns:
- The
ItemStack
on the given slot
-
getUnsafeItem
@Nullable public abstract @Nullable org.bukkit.inventory.ItemStack getUnsafeItem(int slot) Gets theItemStack
on that slot. Depending on the implementation, this method may a copy of or the actual backingItemStack
.It is guaranteed that this method will never return an air / empty item stack. Those are always represented by null.
- Parameters:
slot
- The slot- Returns:
- The
ItemStack
on the given slot.
-
setCloneBackingItem
protected abstract void setCloneBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Clones the givenItemStack
and sets in the backing array of thisInventory
.This method should never be invoked with an air / empty item stack. Those should always be represented by null.
- Parameters:
slot
- The slotitemStack
- TheItemStack
to be set
-
setDirectBackingItem
protected abstract void setDirectBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Sets theItemStack
in the backing array of thisInventory
without explicitly cloning it. Depending on the implementation, theItemStack
might still be cloned.This method should never be invoked with an air / empty item stack. Those should always be represented by null.
- Parameters:
slot
- The slotitemStack
- TheItemStack
to be set
-
getWindows
-
addWindow
Adds anAbstractWindow
to the set ofAbstractWindows
, telling theInventory
that its contents are now being displayed in thatAbstractWindow
.- Parameters:
window
- TheWindow
to be added.
-
removeWindow
Removes anAbstractWindow
from the set ofAbstractWindows
, telling theInventory
that its contents are no longer being displayed in thatAbstractWindow
.- Parameters:
window
- TheAbstractWindow
to be removed.
-
notifyWindows
public void notifyWindows() -
getPreUpdateHandler
Gets the configured pre update handler.- Returns:
- The pre update handler
-
setPreUpdateHandler
public void setPreUpdateHandler(@Nullable @Nullable Consumer<@NotNull ItemPreUpdateEvent> preUpdateHandler) Sets a handler which is called every time something gets updated in theInventory
.- Parameters:
preUpdateHandler
- The new item update handler
-
getPostUpdateHandler
Gets the configured post update handler.- Returns:
- The post update handler
-
setPostUpdateHandler
public void setPostUpdateHandler(@Nullable @Nullable Consumer<@NotNull ItemPostUpdateEvent> inventoryUpdatedHandler) Sets a handler which is called every time after something has been updated in theInventory
.- Parameters:
inventoryUpdatedHandler
- The new handler
-
hasEventHandlers
public boolean hasEventHandlers()Whether thisInventory
has any event handlers.- Returns:
- `true` if this
Inventory
has a pre- or post-update handler.
-
callPreUpdateEvent
public ItemPreUpdateEvent callPreUpdateEvent(@Nullable @Nullable UpdateReason updateReason, int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable @Nullable org.bukkit.inventory.ItemStack newItemStack) Creates anItemPreUpdateEvent
and calls thepreUpdateHandler
to handle it.- Parameters:
updateReason
- TheUpdateReason
.slot
- The slot of the affectedItemStack
.previousItemStack
- TheItemStack
that was previously on that slot.newItemStack
- TheItemStack
that will be on that slot.- Returns:
- The
ItemPreUpdateEvent
after it has been handled by thepreUpdateHandler
.
-
callPostUpdateEvent
public void callPostUpdateEvent(@Nullable @Nullable UpdateReason updateReason, int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable @Nullable org.bukkit.inventory.ItemStack newItemStack) Creates anItemPostUpdateEvent
and calls thepostUpdateHandler
to handle it.- Parameters:
updateReason
- TheUpdateReason
.slot
- The slot of the affectedItemStack
.previousItemStack
- TheItemStack
that was on that slot previously.newItemStack
- TheItemStack
that is on that slot now.
-
getGuiPriority
public int getGuiPriority()Gets the priority for click actions in aGui
, such as shift clicking or cursor collection with multipleVirtualInventories
.- Returns:
- The priority for click actions,
VirtualInventories
with a higher priority get prioritized.
-
setGuiPriority
public void setGuiPriority(int guiPriority) Sets the priority for click actions in aGui
, such as shift-clicking or cursor collection with multipleVirtualInventories
.- Parameters:
guiPriority
- The priority for click actions,VirtualInventories
with a higher priority get prioritized.
-
getMaxStackSize
public int getMaxStackSize(int slot) Gets the maximum stack size for a specific slot.If there is an
ItemStack
on that slot, the returned value will be the minimum of both the slot's max stack size and theItemStack's
max stack size retrieved usingInventoryUtils.stackSizeProvider
.- Parameters:
slot
- The slot- Returns:
- The current maximum allowed stack size on the specific slot.
-
getMaxStackSize
public int getMaxStackSize(int slot, int alternative) Gets the maximum stack size for a specific slot.If there is an
ItemStack
on that slot, the returned value will be the minimum of both the slot's max stack size and theItemStack's
max stack size retrieved usingInventoryUtils.stackSizeProvider
.If there is no
ItemStack
on that slot, the alternative parameter will be used as a potential maximum stack size.- Parameters:
slot
- The slotalternative
- The alternative maximum stack size if noItemStack
is placed on that slot. Should probably be the max stack size of theMaterial
that will be added.- Returns:
- The current maximum allowed stack size on the specific slot.
-
getMaxStackSize
public int getMaxStackSize(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack alternativeFrom) Gets the maximum stack size for a specific slot. If there is anItemStack
on that slot, the returned value will be the minimum of both the slot's and theItemStack's
max stack size retrieved usingInventoryUtils.stackSizeProvider
. If there is noItemStack
on that slot, the alternativeFrom parameter will be used to determine a potential maximum stack size.- Parameters:
slot
- The slotalternativeFrom
- The alternativeItemStack
to determine the potential maximum stack size. Uses 64 if null.- Returns:
- The current maximum allowed stack size on the specific slot.
-
getMaxSlotStackSize
public int getMaxSlotStackSize(int slot, int alternative) Gets the maximum stack size for a specific slot while ignoring theItemStack
on it. The returned value will be a minimum of the slot's maximum stack size and the alternative parameter.- Parameters:
slot
- The slotalternative
- The alternative maximum stack size. Should probably be the max stack size of theMaterial
that will be added.- Returns:
- The maximum stack size on that slot
-
getMaxSlotStackSize
public int getMaxSlotStackSize(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack alternativeFrom) Gets the maximum stack size for a specific slot while ignoring theItemStack
on it. The returned value will be a minimum of the maximum stack size of both the slot and the alternativeFrom parameter.- Parameters:
slot
- The slotalternativeFrom
- The alternativeItemStack
to determine the potential maximum stack size. Uses 64 if null.- Returns:
- The maximum stack size on that slot
-
isSynced
public boolean isSynced(int slot, org.bukkit.inventory.ItemStack assumedStack) Checks if theItemStack
on that slot is the same as the assumedItemStack
provided as parameter.- Parameters:
slot
- The slotassumedStack
- The assumedItemStack
- Returns:
- If the
ItemStack
on that slot is the same as the assumedItemStack
-
isFull
public boolean isFull()Checks if all slots have anItemStack
with their max stack size on them.- Returns:
- Whether this
Inventory
is full.
-
isEmpty
public boolean isEmpty()Checks if there are noItemStacks
in thisInventory
.- Returns:
- Whether this
Inventory
is empty.
-
hasEmptySlot
public boolean hasEmptySlot()Checks whether thisInventory
has at least one empty slot.- Returns:
- Whether this
Inventory
has at least one empty slot.
-
contains
-
containsSimilar
public boolean containsSimilar(org.bukkit.inventory.ItemStack itemStack) - Parameters:
itemStack
- TheItemStack
to match against.- Returns:
- Whether there is any
ItemStack
in thisInventory
similar to the givenItemStack
.
-
count
-
countSimilar
public int countSimilar(org.bukkit.inventory.ItemStack itemStack) - Parameters:
itemStack
- TheItemStack
to match against.- Returns:
- The amount of
ItemStacks
in thisInventory
similar to the givenItemStack
.
-
hasItem
public boolean hasItem(int slot) Checks if there is anItemStack
on that slot.- Parameters:
slot
- The Slot- Returns:
- If there is an
ItemStack
on that slot.
-
getItemAmount
public int getItemAmount(int slot) Gets theItemStack amount
of theItemStack
on the given slot.- Parameters:
slot
- The slot- Returns:
- The amount of items on that slot
-
setItemSilently
public void setItemSilently(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStack
on a specific slot to that one, regardless of what was previously on that slot.This method does not call an
ItemPreUpdateEvent
and ignores the maximum allowed stack size of both theMaterial
and the slot.This method will always be successful.
- Parameters:
slot
- The slotitemStack
- TheItemStack
to set.
-
forceSetItem
public boolean forceSetItem(@Nullable @Nullable UpdateReason updateReason, int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStack
on a specific slot to that one, regardless of what was previously on that slot.
This method ignores the maximum allowed stack size of both theMaterial
and the slot.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.slot
- The slotitemStack
- TheItemStack
to set.- Returns:
- If the action was successful
-
setItem
public boolean setItem(@Nullable @Nullable UpdateReason updateReason, int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStack
on a specific slot to the given one, regardless of what previously was on that slot.
This method will fail if the givenItemStack
does not completely fit because of the maximum allowed stack size.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.slot
- The slotitemStack
- TheItemStack
to set.- Returns:
- If the action was successful
-
modifyItem
public boolean modifyItem(@Nullable @Nullable UpdateReason updateReason, int slot, @NotNull @NotNull Consumer<@Nullable org.bukkit.inventory.ItemStack> modifier) Changes theItemStack
on a specific slot based on the currentItemStack
on that slot, using a modifier consumer.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.slot
- The slot.modifier
- The modifier consumer. Accepts the currentItemStack
and modifies it.- Returns:
- If the action was successful.
-
replaceItem
public boolean replaceItem(@Nullable @Nullable UpdateReason updateReason, int slot, @NotNull @NotNull Function<@Nullable org.bukkit.inventory.ItemStack, @Nullable org.bukkit.inventory.ItemStack> function) Replaces theItemStack
on a specific slot based on the currentItemStack
on that slot, using a replace function.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.slot
- The slot.function
- The replace function. The argument is the currentItemStack
, the return value is the newItemStack
.- Returns:
- If the action was successful.
-
putItem
public int putItem(@Nullable @Nullable UpdateReason updateReason, int slot, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack) Adds anItemStack
on a specific slot and returns the amount of items that did not fit on that slot.This method will fail if there is an
ItemStack
on that slot that is not similar to the given one.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.slot
- The slotitemStack
- TheItemStack
to add.- Returns:
- The amount of items that did not fit on that slot.
-
setItemAmount
Sets the amount of anItemStack
on a slot to the given value while respecting the max allowed stack size on that slot.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.slot
- The slotamount
- The amount to change to.- Returns:
- The amount that it actually changed to.
- Throws:
IllegalStateException
- If there is noItemStack
on that slot.
-
addItemAmount
Adds a specific amount to anItemStack
on a slot while respecting the maximum allowed stack size on that slot. Returns 0 if there is noItemStack
on that slot.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.slot
- The slotamount
- The amount to add- Returns:
- The amount that was actually added.
-
addItem
public int addItem(@Nullable @Nullable UpdateReason updateReason, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack) Adds anItemStack
to theInventory
. This method does not work the same way as Bukkit's addItem method as it respects the max stack size of the item type.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.itemStack
- TheItemStack
to add- Returns:
- The amount of items that didn't fit
- See Also:
-
simulateAdd
public int[] simulateAdd(@NotNull @NotNull org.bukkit.inventory.ItemStack first, @NotNull @NotNull org.bukkit.inventory.ItemStack @NotNull ... rest) Simulates addingItemStack
s to thisInventory
and returns the amount ofItemStack
s that did not fit.- Parameters:
first
- The firstItemStack
to use.rest
- The rest of theItemStacks
to use.- Returns:
- An array of integers representing the leftover amount for each
ItemStack
provided. The size of this array is always equal to the amount ofItemStack
s provided as method parameters.
-
simulateAdd
public int[] simulateAdd(@NotNull @NotNull List<@NotNull org.bukkit.inventory.ItemStack> itemStacks) Simulates addingItemStack
s to thisInventory
and returns the amount ofItemStack
s that did not fit.- Parameters:
itemStacks
- TheItemStack
to use.- Returns:
- An array of integers representing the leftover amount for each
ItemStack
provided. The size of this array is always equal to the amount ofItemStack
s provided as method parameters.
-
canHold
public boolean canHold(@NotNull @NotNull org.bukkit.inventory.ItemStack first, @NotNull @NotNull org.bukkit.inventory.ItemStack @NotNull ... rest) - Parameters:
first
- The firstItemStack
to use.rest
- The rest of theItemStacks
to use.- Returns:
- If all provided
ItemStack
s would fit if added.
-
canHold
- Parameters:
itemStacks
- TheItemStack
to use.- Returns:
- If all provided
ItemStack
s would fit if added.
-
simulateSingleAdd
public int simulateSingleAdd(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack) Returns the amount of items that wouldn't fit in the inventory when added.
Note: This method does not add anyItemStack
s to theInventory
.- Parameters:
itemStack
- TheItemStack
to use- Returns:
- How many items wouldn't fit in the inventory when added
-
simulateMultiAdd
public int[] simulateMultiAdd(@NotNull @NotNull List<@NotNull org.bukkit.inventory.ItemStack> itemStacks) Simulates adding multipleItemStack
s to thisInventory
and returns the amount ofItemStack
s that did not fit.- Parameters:
itemStacks
- TheItemStack
to be used in the simulation- Returns:
- An array of integers representing the leftover amount for each
ItemStack
provided. The size of this array is always equal to the amount ofItemStacks
provided as method parameters.
-
collectSimilar
public int collectSimilar(@Nullable @Nullable UpdateReason updateReason, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack) Finds allItemStack
s similar to the providedItemStack
and removes them from their slot until the amount of the givenItemStack
reaches its maximum stack size.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.itemStack
- TheItemStack
to match against and to use for the base amount.- Returns:
- The amount of collected items plus the amount of the provided
ItemStack
. At most the max stack size of the givenItemStack
.
-
collectSimilar
public int collectSimilar(@Nullable @Nullable UpdateReason updateReason, @NotNull @NotNull org.bukkit.inventory.ItemStack template, int baseAmount) Finds allItemStack
s similar to the providedItemStack
and removes them from their slot until the maximum stack size of theMaterial
is reached.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.template
- TheItemStack
to match against.baseAmount
- The base item amount to assume. For example, with a base amount of 32 and a max stack size of 64, this method will at most collect 32 other items.- Returns:
- The amount of collected items plus the base amount. At most the max stack size of the template
ItemStack
.
-
removeIf
public int removeIf(@Nullable @Nullable UpdateReason updateReason, @NotNull @NotNull Predicate<@NotNull org.bukkit.inventory.ItemStack> predicate) Removes allItemStacks
matching the givenPredicate
.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.predicate
- ThePredicate
to use.- Returns:
- The amount of items that were removed.
-
removeFirst
public int removeFirst(@Nullable @Nullable UpdateReason updateReason, int amount, @NotNull @NotNull Predicate<@NotNull org.bukkit.inventory.ItemStack> predicate) Removes the first nItemStacks
matching the givenPredicate
.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.amount
- The maximum amount ofItemStacks
to remove.predicate
- ThePredicate
to use.- Returns:
- The amount of items that were removed.
-
removeSimilar
public int removeSimilar(@Nullable @Nullable UpdateReason updateReason, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack) Removes allItemStacks
that are similar to the specifiedItemStack
.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.itemStack
- TheItemStack
to match against.- Returns:
- The amount of items that were removed.
-
removeFirstSimilar
public int removeFirstSimilar(@Nullable @Nullable UpdateReason updateReason, int amount, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack) Removes the first nItemStacks
that are similar to the specifiedItemStack
.- Parameters:
updateReason
- The reason used in theItemPreUpdateEvent
andItemPostUpdateEvent
.amount
- The maximum amount ofItemStacks
to remove.itemStack
- TheItemStack
to match against.- Returns:
- The amount of items that were removed.
-