Class ReferencingInventory
Inventory
which is backed by a bukkit Inventory
.
Changes in this inventory are applied in the referenced inventory and changes in the bukkit inventory are visible in this inventory.
Changes done using the methods provided by Inventory
will cause displaying
Windows
to be notified
, but changes
done directly in the bukkit inventory will not. Therefore, if embedded in a Gui
, it is necessary to call
Inventory.notifyWindows()
manually in order for changes to be displayed.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final @NotNull org.bukkit.inventory.Inventory
protected final @NotNull BiFunction
<@NotNull org.bukkit.inventory.Inventory, @NotNull Integer, @Nullable org.bukkit.inventory.ItemStack> protected final @NotNull TriConsumer
<@NotNull org.bukkit.inventory.Inventory, @NotNull Integer, @Nullable org.bukkit.inventory.ItemStack> protected final @NotNull Function
<@NotNull org.bukkit.inventory.Inventory, @Nullable org.bukkit.inventory.ItemStack @NotNull []> protected final int @NotNull []
protected final int
-
Constructor Summary
ConstructorDescriptionReferencingInventory
(@NotNull org.bukkit.inventory.Inventory inventory, @NotNull Function<@NotNull org.bukkit.inventory.Inventory, @Nullable org.bukkit.inventory.ItemStack @NotNull []> itemsGetter, @NotNull BiFunction<@NotNull org.bukkit.inventory.Inventory, @NotNull Integer, @Nullable org.bukkit.inventory.ItemStack> itemGetter, @NotNull TriConsumer<@NotNull org.bukkit.inventory.Inventory, @NotNull Integer, @Nullable org.bukkit.inventory.ItemStack> itemSetter) Constructs a newReferencingInventory
. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull ReferencingInventory
fromContents
(@NotNull org.bukkit.inventory.Inventory inventory) static @NotNull ReferencingInventory
fromReversedPlayerStorageContents
(@NotNull org.bukkit.inventory.PlayerInventory inventory) Creates a newReferencingInventory
with a reversed view of thePlayerInventory's
storage contents
, where the last hotbar slot is the first slot and the top left slot is the last slot.static @NotNull ReferencingInventory
fromStorageContents
(@NotNull org.bukkit.inventory.Inventory inventory) Creates a newReferencingInventory
which references only thestorage contents
of the specifiedInventory
.@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.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.Methods inherited from class xyz.xenondevs.invui.inventory.Inventory
addItem, addItemAmount, addWindow, callPostUpdateEvent, callPreUpdateEvent, canHold, canHold, collectSimilar, collectSimilar, contains, containsSimilar, count, countSimilar, forceSetItem, getGuiPriority, getItemAmount, getMaxSlotStackSize, getMaxSlotStackSize, getMaxStackSize, getMaxStackSize, getMaxStackSize, getPostUpdateHandler, getPreUpdateHandler, getWindows, hasEmptySlot, hasEventHandlers, hasItem, isEmpty, isFull, isSynced, modifyItem, notifyWindows, putItem, removeFirst, removeFirstSimilar, removeIf, removeSimilar, removeWindow, replaceItem, setGuiPriority, setItem, setItemAmount, setItemSilently, setPostUpdateHandler, setPreUpdateHandler, simulateAdd, simulateAdd, simulateMultiAdd, simulateSingleAdd
-
Field Details
-
inventory
@NotNull protected final @NotNull org.bukkit.inventory.Inventory inventory -
itemsGetter
@NotNull protected final @NotNull Function<@NotNull org.bukkit.inventory.Inventory,@Nullable org.bukkit.inventory.ItemStack @NotNull []> itemsGetter -
itemGetter
@NotNull protected final @NotNull BiFunction<@NotNull org.bukkit.inventory.Inventory,@NotNull Integer, itemGetter@Nullable org.bukkit.inventory.ItemStack> -
itemSetter
@NotNull protected final @NotNull TriConsumer<@NotNull org.bukkit.inventory.Inventory,@NotNull Integer, itemSetter@Nullable org.bukkit.inventory.ItemStack> -
size
protected final int size -
maxStackSizes
protected final int @NotNull [] maxStackSizes
-
-
Constructor Details
-
ReferencingInventory
public ReferencingInventory(@NotNull @NotNull org.bukkit.inventory.Inventory inventory, @NotNull @NotNull Function<@NotNull org.bukkit.inventory.Inventory, @Nullable org.bukkit.inventory.ItemStack @NotNull []> itemsGetter, @NotNull @NotNull BiFunction<@NotNull org.bukkit.inventory.Inventory, @NotNull Integer, @Nullable org.bukkit.inventory.ItemStack> itemGetter, @NotNull @NotNull TriConsumer<@NotNull org.bukkit.inventory.Inventory, @NotNull Integer, @Nullable org.bukkit.inventory.ItemStack> itemSetter) Constructs a newReferencingInventory
.- Parameters:
inventory
- TheInventory
to reference.itemsGetter
- AFunction
which returns a copy of theItemStacks
of theInventory
.itemGetter
- ABiFunction
which returns a copy of theItemStack
on the specified slot.itemSetter
- ATriConsumer
which copies and then sets theItemStack
on the specified slot.
-
-
Method Details
-
fromStorageContents
@NotNull public static @NotNull ReferencingInventory fromStorageContents(@NotNull @NotNull org.bukkit.inventory.Inventory inventory) Creates a newReferencingInventory
which references only thestorage contents
of the specifiedInventory
.- Parameters:
inventory
- TheInventory
to reference.- Returns:
- The new
ReferencingInventory
.
-
fromContents
@NotNull public static @NotNull ReferencingInventory fromContents(@NotNull @NotNull org.bukkit.inventory.Inventory inventory) - Parameters:
inventory
- TheInventory
to reference.- Returns:
- The new
ReferencingInventory
.
-
fromReversedPlayerStorageContents
@NotNull public static @NotNull ReferencingInventory fromReversedPlayerStorageContents(@NotNull @NotNull org.bukkit.inventory.PlayerInventory inventory) Creates a newReferencingInventory
with a reversed view of thePlayerInventory's
storage contents
, where the last hotbar slot is the first slot and the top left slot is the last slot.- Parameters:
inventory
- ThePlayerInventory
to reference.- Returns:
- The new
ReferencingInventory
.
-
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
-