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
ItemStacksof typeMaterial.AIRorItemStack.getAmount()== 0.
EmptyItemStacksare represented bynull. -
Unless otherwise specified, all methods will return a clone of the actual backing
ItemStack.
Changes to returnedItemStackswill never affect theInventory. -
Unless otherwise specified, all methods accepting
ItemStackswill always clone them before putting them in the backing array / inventory.
Changes to the passedItemStacksafter calling a method will never affect theInventory.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddItem(@Nullable UpdateReason updateReason, @NotNull org.bukkit.inventory.ItemStack itemStack) Adds anItemStackto theInventory.intaddItemAmount(@Nullable UpdateReason updateReason, int slot, int amount) Adds a specific amount to anItemStackon a slot while respecting the maximum allowed stack size on that slot.voidaddWindow(AbstractWindow window) Adds anAbstractWindowto the set ofAbstractWindows, telling theInventorythat its contents are now being displayed in thatAbstractWindow.voidcallPostUpdateEvent(@Nullable UpdateReason updateReason, int slot, @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable org.bukkit.inventory.ItemStack newItemStack) Creates anItemPostUpdateEventand calls thepostUpdateHandlerto handle it.callPreUpdateEvent(@Nullable UpdateReason updateReason, int slot, @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable org.bukkit.inventory.ItemStack newItemStack) Creates anItemPreUpdateEventand calls thepreUpdateHandlerto handle it.booleanbooleancanHold(@NotNull org.bukkit.inventory.ItemStack first, @NotNull org.bukkit.inventory.ItemStack @NotNull ... rest) intcollectSimilar(@Nullable UpdateReason updateReason, @NotNull org.bukkit.inventory.ItemStack itemStack) Finds allItemStacks similar to the providedItemStackand removes them from their slot until the amount of the givenItemStackreaches its maximum stack size.intcollectSimilar(@Nullable UpdateReason updateReason, @NotNull org.bukkit.inventory.ItemStack template, int baseAmount) Finds allItemStacks similar to the providedItemStackand removes them from their slot until the maximum stack size of theMaterialis reached.booleanbooleancontainsSimilar(org.bukkit.inventory.ItemStack itemStack) intintcountSimilar(org.bukkit.inventory.ItemStack itemStack) booleanforceSetItem(@Nullable UpdateReason updateReason, int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStackon a specific slot to that one, regardless of what was previously on that slot.intGets the priority for click actions in aGui, such as shift clicking or cursor collection with multipleVirtualInventories.abstract @Nullable org.bukkit.inventory.ItemStackgetItem(int slot) Gets a clone of theItemStackon that slot.intgetItemAmount(int slot) Gets theItemStack amountof theItemStackon the given slot.abstract @Nullable org.bukkit.inventory.ItemStack @NotNull []getItems()Gets a copy of the contents of thisInventory.abstract intgetMaxSlotStackSize(int slot) Gets the maximum stack size for a specific slot while ignoring max stack size of theItemStackon it.intgetMaxSlotStackSize(int slot, int alternative) Gets the maximum stack size for a specific slot while ignoring theItemStackon it.intgetMaxSlotStackSize(int slot, @Nullable org.bukkit.inventory.ItemStack alternativeFrom) Gets the maximum stack size for a specific slot while ignoring theItemStackon it.intgetMaxStackSize(int slot) Gets the maximum stack size for a specific slot.intgetMaxStackSize(int slot, int alternative) Gets the maximum stack size for a specific slot.intgetMaxStackSize(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 intgetSize()Gets the size of thisInventory.abstract @Nullable org.bukkit.inventory.ItemStackgetUnsafeItem(int slot) Gets theItemStackon that slot.abstract @Nullable org.bukkit.inventory.ItemStack @NotNull []Gets theItemStacksthisInventorycontains.booleanChecks whether thisInventoryhas at least one empty slot.booleanWhether thisInventoryhas any event handlers.booleanhasItem(int slot) Checks if there is anItemStackon that slot.booleanisEmpty()Checks if there are noItemStacksin thisInventory.booleanisFull()Checks if all slots have anItemStackwith their max stack size on them.booleanisSynced(int slot, org.bukkit.inventory.ItemStack assumedStack) Checks if theItemStackon that slot is the same as the assumedItemStackprovided as parameter.booleanmodifyItem(@Nullable UpdateReason updateReason, int slot, @NotNull Consumer<@Nullable org.bukkit.inventory.ItemStack> modifier) Changes theItemStackon a specific slot based on the currentItemStackon that slot, using a modifier consumer.voidintputItem(@Nullable UpdateReason updateReason, int slot, @NotNull org.bukkit.inventory.ItemStack itemStack) Adds anItemStackon a specific slot and returns the amount of items that did not fit on that slot.intremoveFirst(@Nullable UpdateReason updateReason, int amount, @NotNull Predicate<@NotNull org.bukkit.inventory.ItemStack> predicate) Removes the first nItemStacksmatching the givenPredicate.intremoveFirstSimilar(@Nullable UpdateReason updateReason, int amount, @NotNull org.bukkit.inventory.ItemStack itemStack) Removes the first nItemStacksthat are similar to the specifiedItemStack.intremoveIf(@Nullable UpdateReason updateReason, @NotNull Predicate<@NotNull org.bukkit.inventory.ItemStack> predicate) Removes allItemStacksmatching the givenPredicate.intremoveSimilar(@Nullable UpdateReason updateReason, @NotNull org.bukkit.inventory.ItemStack itemStack) Removes allItemStacksthat are similar to the specifiedItemStack.voidremoveWindow(AbstractWindow window) Removes anAbstractWindowfrom the set ofAbstractWindows, telling theInventorythat its contents are no longer being displayed in thatAbstractWindow.booleanreplaceItem(@Nullable UpdateReason updateReason, int slot, @NotNull Function<@Nullable org.bukkit.inventory.ItemStack, @Nullable org.bukkit.inventory.ItemStack> function) Replaces theItemStackon a specific slot based on the currentItemStackon that slot, using a replace function.protected abstract voidsetCloneBackingItem(int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Clones the givenItemStackand sets in the backing array of thisInventory.protected abstract voidsetDirectBackingItem(int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Sets theItemStackin the backing array of thisInventorywithout explicitly cloning it.voidsetGuiPriority(int guiPriority) Sets the priority for click actions in aGui, such as shift-clicking or cursor collection with multipleVirtualInventories.booleansetItem(@Nullable UpdateReason updateReason, int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStackon a specific slot to the given one, regardless of what previously was on that slot.intsetItemAmount(@Nullable UpdateReason updateReason, int slot, int amount) Sets the amount of anItemStackon a slot to the given value while respecting the max allowed stack size on that slot.voidsetItemSilently(int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStackon a specific slot to that one, regardless of what was previously on that slot.voidsetPostUpdateHandler(@Nullable Consumer<@NotNull ItemPostUpdateEvent> inventoryUpdatedHandler) Sets a handler which is called every time after something has been updated in theInventory.voidsetPreUpdateHandler(@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 addingItemStacks to thisInventoryand returns the amount ofItemStacks that did not fit.int[]simulateAdd(@NotNull org.bukkit.inventory.ItemStack first, @NotNull org.bukkit.inventory.ItemStack @NotNull ... rest) Simulates addingItemStacks to thisInventoryand returns the amount ofItemStacks that did not fit.int[]simulateMultiAdd(@NotNull List<@NotNull org.bukkit.inventory.ItemStack> itemStacks) Simulates adding multipleItemStacks to thisInventoryand returns the amount ofItemStacks that did not fit.intsimulateSingleAdd(@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
Inventoryhas.
-
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 theItemStackon 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
ItemStacksthisInventorycontains.
-
getUnsafeItems
@Nullable public abstract @Nullable org.bukkit.inventory.ItemStack @NotNull [] getUnsafeItems()Gets theItemStacksthisInventorycontains. 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
ItemStacksthisInventorycontains.
-
getItem
@Nullable public abstract @Nullable org.bukkit.inventory.ItemStack getItem(int slot) Gets a clone of theItemStackon 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
ItemStackon the given slot
-
getUnsafeItem
@Nullable public abstract @Nullable org.bukkit.inventory.ItemStack getUnsafeItem(int slot) Gets theItemStackon 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
ItemStackon the given slot.
-
setCloneBackingItem
protected abstract void setCloneBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Clones the givenItemStackand 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- TheItemStackto be set
-
setDirectBackingItem
protected abstract void setDirectBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Sets theItemStackin the backing array of thisInventorywithout explicitly cloning it. Depending on the implementation, theItemStackmight 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- TheItemStackto be set
-
getWindows
-
addWindow
Adds anAbstractWindowto the set ofAbstractWindows, telling theInventorythat its contents are now being displayed in thatAbstractWindow.- Parameters:
window- TheWindowto be added.
-
removeWindow
Removes anAbstractWindowfrom the set ofAbstractWindows, telling theInventorythat its contents are no longer being displayed in thatAbstractWindow.- Parameters:
window- TheAbstractWindowto 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 thisInventoryhas any event handlers.- Returns:
- `true` if this
Inventoryhas 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 anItemPreUpdateEventand calls thepreUpdateHandlerto handle it.- Parameters:
updateReason- TheUpdateReason.slot- The slot of the affectedItemStack.previousItemStack- TheItemStackthat was previously on that slot.newItemStack- TheItemStackthat will be on that slot.- Returns:
- The
ItemPreUpdateEventafter 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 anItemPostUpdateEventand calls thepostUpdateHandlerto handle it.- Parameters:
updateReason- TheUpdateReason.slot- The slot of the affectedItemStack.previousItemStack- TheItemStackthat was on that slot previously.newItemStack- TheItemStackthat 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,
VirtualInventorieswith 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,VirtualInventorieswith a higher priority get prioritized.
-
getMaxStackSize
public int getMaxStackSize(int slot) Gets the maximum stack size for a specific slot.If there is an
ItemStackon that slot, the returned value will be the minimum of both the slot's max stack size and theItemStack'smax 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
ItemStackon that slot, the returned value will be the minimum of both the slot's max stack size and theItemStack'smax stack size retrieved usingInventoryUtils.stackSizeProvider.If there is no
ItemStackon that slot, the alternative parameter will be used as a potential maximum stack size.- Parameters:
slot- The slotalternative- The alternative maximum stack size if noItemStackis placed on that slot. Should probably be the max stack size of theMaterialthat 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 anItemStackon that slot, the returned value will be the minimum of both the slot's and theItemStack'smax stack size retrieved usingInventoryUtils.stackSizeProvider. If there is noItemStackon that slot, the alternativeFrom parameter will be used to determine a potential maximum stack size.- Parameters:
slot- The slotalternativeFrom- The alternativeItemStackto 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 theItemStackon 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 theMaterialthat 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 theItemStackon 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 alternativeItemStackto 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 theItemStackon that slot is the same as the assumedItemStackprovided as parameter.- Parameters:
slot- The slotassumedStack- The assumedItemStack- Returns:
- If the
ItemStackon that slot is the same as the assumedItemStack
-
isFull
public boolean isFull()Checks if all slots have anItemStackwith their max stack size on them.- Returns:
- Whether this
Inventoryis full.
-
isEmpty
public boolean isEmpty()Checks if there are noItemStacksin thisInventory.- Returns:
- Whether this
Inventoryis empty.
-
hasEmptySlot
public boolean hasEmptySlot()Checks whether thisInventoryhas at least one empty slot.- Returns:
- Whether this
Inventoryhas at least one empty slot.
-
contains
-
containsSimilar
public boolean containsSimilar(org.bukkit.inventory.ItemStack itemStack) - Parameters:
itemStack- TheItemStackto match against.- Returns:
- Whether there is any
ItemStackin thisInventorysimilar to the givenItemStack.
-
count
-
countSimilar
public int countSimilar(org.bukkit.inventory.ItemStack itemStack) - Parameters:
itemStack- TheItemStackto match against.- Returns:
- The amount of
ItemStacksin thisInventorysimilar to the givenItemStack.
-
hasItem
public boolean hasItem(int slot) Checks if there is anItemStackon that slot.- Parameters:
slot- The Slot- Returns:
- If there is an
ItemStackon that slot.
-
getItemAmount
public int getItemAmount(int slot) Gets theItemStack amountof theItemStackon 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 theItemStackon a specific slot to that one, regardless of what was previously on that slot.This method does not call an
ItemPreUpdateEventand ignores the maximum allowed stack size of both theMaterialand the slot.This method will always be successful.
- Parameters:
slot- The slotitemStack- TheItemStackto set.
-
forceSetItem
public boolean forceSetItem(@Nullable @Nullable UpdateReason updateReason, int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Changes theItemStackon a specific slot to that one, regardless of what was previously on that slot.
This method ignores the maximum allowed stack size of both theMaterialand the slot.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.slot- The slotitemStack- TheItemStackto 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 theItemStackon a specific slot to the given one, regardless of what previously was on that slot.
This method will fail if the givenItemStackdoes not completely fit because of the maximum allowed stack size.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.slot- The slotitemStack- TheItemStackto 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 theItemStackon a specific slot based on the currentItemStackon that slot, using a modifier consumer.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.slot- The slot.modifier- The modifier consumer. Accepts the currentItemStackand 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 theItemStackon a specific slot based on the currentItemStackon that slot, using a replace function.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.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 anItemStackon a specific slot and returns the amount of items that did not fit on that slot.This method will fail if there is an
ItemStackon that slot that is not similar to the given one.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.slot- The slotitemStack- TheItemStackto add.- Returns:
- The amount of items that did not fit on that slot.
-
setItemAmount
Sets the amount of anItemStackon a slot to the given value while respecting the max allowed stack size on that slot.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.slot- The slotamount- The amount to change to.- Returns:
- The amount that it actually changed to.
- Throws:
IllegalStateException- If there is noItemStackon that slot.
-
addItemAmount
Adds a specific amount to anItemStackon a slot while respecting the maximum allowed stack size on that slot. Returns 0 if there is noItemStackon that slot.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.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 anItemStackto 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 theItemPreUpdateEventandItemPostUpdateEvent.itemStack- TheItemStackto 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 addingItemStacks to thisInventoryand returns the amount ofItemStacks that did not fit.- Parameters:
first- The firstItemStackto use.rest- The rest of theItemStacksto use.- Returns:
- An array of integers representing the leftover amount for each
ItemStackprovided. The size of this array is always equal to the amount ofItemStacks provided as method parameters.
-
simulateAdd
public int[] simulateAdd(@NotNull @NotNull List<@NotNull org.bukkit.inventory.ItemStack> itemStacks) Simulates addingItemStacks to thisInventoryand returns the amount ofItemStacks that did not fit.- Parameters:
itemStacks- TheItemStackto use.- Returns:
- An array of integers representing the leftover amount for each
ItemStackprovided. The size of this array is always equal to the amount ofItemStacks 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 firstItemStackto use.rest- The rest of theItemStacksto use.- Returns:
- If all provided
ItemStacks would fit if added.
-
canHold
- Parameters:
itemStacks- TheItemStackto use.- Returns:
- If all provided
ItemStacks 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 anyItemStacks to theInventory.- Parameters:
itemStack- TheItemStackto 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 multipleItemStacks to thisInventoryand returns the amount ofItemStacks that did not fit.- Parameters:
itemStacks- TheItemStackto be used in the simulation- Returns:
- An array of integers representing the leftover amount for each
ItemStackprovided. The size of this array is always equal to the amount ofItemStacksprovided as method parameters.
-
collectSimilar
public int collectSimilar(@Nullable @Nullable UpdateReason updateReason, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack) Finds allItemStacks similar to the providedItemStackand removes them from their slot until the amount of the givenItemStackreaches its maximum stack size.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.itemStack- TheItemStackto 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 allItemStacks similar to the providedItemStackand removes them from their slot until the maximum stack size of theMaterialis reached.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.template- TheItemStackto 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 allItemStacksmatching the givenPredicate.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.predicate- ThePredicateto 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 nItemStacksmatching the givenPredicate.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.amount- The maximum amount ofItemStacksto remove.predicate- ThePredicateto 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 allItemStacksthat are similar to the specifiedItemStack.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.itemStack- TheItemStackto 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 nItemStacksthat are similar to the specifiedItemStack.- Parameters:
updateReason- The reason used in theItemPreUpdateEventandItemPostUpdateEvent.amount- The maximum amount ofItemStacksto remove.itemStack- TheItemStackto match against.- Returns:
- The amount of items that were removed.
-