Package xyz.xenondevs.invui.inventory
Class ObscuredInventory
java.lang.Object
xyz.xenondevs.invui.inventory.Inventory
xyz.xenondevs.invui.inventory.ObscuredInventory
-
Constructor Summary
ConstructorDescriptionObscuredInventory
(@NotNull Inventory inventory, @NotNull IntPredicate isObscured) Constructs a newObscuredInventory
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
callPostUpdateEvent
(@Nullable UpdateReason updateReason, int slot, @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable org.bukkit.inventory.ItemStack newItemStack) Creates anItemPostUpdateEvent
and calls theInventory.postUpdateHandler
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 theInventory.preUpdateHandler
to handle it.int
Gets the priority for click actions in aGui
, such as shift clicking or cursor collection with multipleVirtualInventories
.@Nullable org.bukkit.inventory.ItemStack
getItem
(int slot) Gets a clone of theItemStack
on that slot.@Nullable org.bukkit.inventory.ItemStack @NotNull []
getItems()
Gets a copy of the contents of thisInventory
.int
getMaxSlotStackSize
(int slot) Gets the maximum stack size for a specific slot while ignoring max stack size of theItemStack
on it.int @NotNull []
Gets the array of max stack sizes for thisInventory
.int
getSize()
Gets the size of thisInventory
.@Nullable org.bukkit.inventory.ItemStack
getUnsafeItem
(int slot) Gets theItemStack
on that slot.@Nullable org.bukkit.inventory.ItemStack @NotNull []
Gets theItemStacks
thisInventory
contains.boolean
Whether thisInventory
has any event handlers.void
protected void
setCloneBackingItem
(int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Clones the givenItemStack
and sets in the backing array of thisInventory
.protected 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
.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
.Methods inherited from class xyz.xenondevs.invui.inventory.Inventory
addItem, addItemAmount, addWindow, canHold, canHold, collectSimilar, collectSimilar, contains, containsSimilar, count, countSimilar, forceSetItem, getItemAmount, getMaxSlotStackSize, getMaxSlotStackSize, getMaxStackSize, getMaxStackSize, getMaxStackSize, getPostUpdateHandler, getPreUpdateHandler, getWindows, hasEmptySlot, hasItem, isEmpty, isFull, isSynced, modifyItem, putItem, removeFirst, removeFirstSimilar, removeIf, removeSimilar, removeWindow, replaceItem, setItem, setItemAmount, setItemSilently, simulateAdd, simulateAdd, simulateMultiAdd, simulateSingleAdd
-
Constructor Details
-
ObscuredInventory
public ObscuredInventory(@NotNull @NotNull Inventory inventory, @NotNull @NotNull IntPredicate isObscured) Constructs a newObscuredInventory
.- Parameters:
inventory
- TheInventory
to delegate to.isObscured
- AIntPredicate
that returns true for slots that should be hidden.
-
-
Method Details
-
getSize
public int getSize()Description copied from class:Inventory
Gets the size of thisInventory
. -
getMaxStackSizes
public int @NotNull [] getMaxStackSizes()Description copied from class:Inventory
Gets the array of max stack sizes for thisInventory
.- Specified by:
getMaxStackSizes
in classInventory
- Returns:
- The array defining the max stack sizes for this
Inventory
-
getMaxSlotStackSize
public int getMaxSlotStackSize(int slot) Description copied from class:Inventory
Gets the maximum stack size for a specific slot while ignoring max stack size of theItemStack
on it.- Specified by:
getMaxSlotStackSize
in classInventory
- Parameters:
slot
- The slot- Returns:
- The maximum stack size on that slo
-
getItems
@Nullable public @Nullable org.bukkit.inventory.ItemStack @NotNull [] getItems()Description copied from class:Inventory
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.
-
getUnsafeItems
@Nullable public @Nullable org.bukkit.inventory.ItemStack @NotNull [] getUnsafeItems()Description copied from class:Inventory
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.
- Specified by:
getUnsafeItems
in classInventory
- Returns:
- The
ItemStacks
thisInventory
contains.
-
getItem
@Nullable public @Nullable org.bukkit.inventory.ItemStack getItem(int slot) Description copied from class:Inventory
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.
-
getUnsafeItem
@Nullable public @Nullable org.bukkit.inventory.ItemStack getUnsafeItem(int slot) Description copied from class:Inventory
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.
- Specified by:
getUnsafeItem
in classInventory
- Parameters:
slot
- The slot- Returns:
- The
ItemStack
on the given slot.
-
setCloneBackingItem
protected void setCloneBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Description copied from class:Inventory
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.
- Specified by:
setCloneBackingItem
in classInventory
- Parameters:
slot
- The slotitemStack
- TheItemStack
to be set
-
setDirectBackingItem
protected void setDirectBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Description copied from class:Inventory
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.
- Specified by:
setDirectBackingItem
in classInventory
- Parameters:
slot
- The slotitemStack
- TheItemStack
to be set
-
notifyWindows
public void notifyWindows()Description copied from class:Inventory
Notifies allWindow
s displaying thisInventory
to update their representativeItemStack
s. This method should only be called manually in very specific cases like when theItemMeta
of anItemStack
in this inventory has changed.- Overrides:
notifyWindows
in classInventory
-
callPreUpdateEvent
public ItemPreUpdateEvent callPreUpdateEvent(@Nullable @Nullable UpdateReason updateReason, int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable @Nullable org.bukkit.inventory.ItemStack newItemStack) Description copied from class:Inventory
Creates anItemPreUpdateEvent
and calls theInventory.preUpdateHandler
to handle it.- Overrides:
callPreUpdateEvent
in classInventory
- 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 theInventory.preUpdateHandler
.
-
callPostUpdateEvent
public void callPostUpdateEvent(@Nullable @Nullable UpdateReason updateReason, int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable @Nullable org.bukkit.inventory.ItemStack newItemStack) Description copied from class:Inventory
Creates anItemPostUpdateEvent
and calls theInventory.postUpdateHandler
to handle it.- Overrides:
callPostUpdateEvent
in classInventory
- 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.
-
hasEventHandlers
public boolean hasEventHandlers()Description copied from class:Inventory
Whether thisInventory
has any event handlers.- Overrides:
hasEventHandlers
in classInventory
- Returns:
- `true` if this
Inventory
has a pre- or post-update handler.
-
setPostUpdateHandler
public void setPostUpdateHandler(@Nullable @Nullable Consumer<@NotNull ItemPostUpdateEvent> inventoryUpdatedHandler) Description copied from class:Inventory
Sets a handler which is called every time after something has been updated in theInventory
.- Overrides:
setPostUpdateHandler
in classInventory
- Parameters:
inventoryUpdatedHandler
- The new handler
-
setPreUpdateHandler
public void setPreUpdateHandler(@Nullable @Nullable Consumer<@NotNull ItemPreUpdateEvent> preUpdateHandler) Description copied from class:Inventory
Sets a handler which is called every time something gets updated in theInventory
.- Overrides:
setPreUpdateHandler
in classInventory
- Parameters:
preUpdateHandler
- The new item update handler
-
getGuiPriority
public int getGuiPriority()Description copied from class:Inventory
Gets the priority for click actions in aGui
, such as shift clicking or cursor collection with multipleVirtualInventories
.- Overrides:
getGuiPriority
in classInventory
- Returns:
- The priority for click actions,
VirtualInventories
with a higher priority get prioritized.
-
setGuiPriority
public void setGuiPriority(int guiPriority) Description copied from class:Inventory
Sets the priority for click actions in aGui
, such as shift-clicking or cursor collection with multipleVirtualInventories
.- Overrides:
setGuiPriority
in classInventory
- Parameters:
guiPriority
- The priority for click actions,VirtualInventories
with a higher priority get prioritized.
-