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
FieldsModifier and TypeFieldDescriptionprotected final @NotNull org.bukkit.inventory.Inventoryprotected 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
ConstructorsConstructorDescriptionReferencingInventory(@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 ReferencingInventoryfromContents(@NotNull org.bukkit.inventory.Inventory inventory) static @NotNull ReferencingInventoryfromReversedPlayerStorageContents(@NotNull org.bukkit.inventory.PlayerInventory inventory) Creates a newReferencingInventorywith a reversed view of thePlayerInventory'sstorage contents, where the last hotbar slot is the first slot and the top left slot is the last slot.static @NotNull ReferencingInventoryfromStorageContents(@NotNull org.bukkit.inventory.Inventory inventory) Creates a newReferencingInventorywhich references only thestorage contentsof the specifiedInventory.@Nullable org.bukkit.inventory.ItemStackgetItem(int slot) Gets a clone of theItemStackon that slot.@Nullable org.bukkit.inventory.ItemStack @NotNull []getItems()Gets a copy of the contents of thisInventory.intgetMaxSlotStackSize(int slot) Gets the maximum stack size for a specific slot while ignoring max stack size of theItemStackon it.int @NotNull []Gets the array of max stack sizes for thisInventory.intgetSize()Gets the size of thisInventory.@Nullable org.bukkit.inventory.ItemStackgetUnsafeItem(int slot) Gets theItemStackon that slot.@Nullable org.bukkit.inventory.ItemStack @NotNull []Gets theItemStacksthisInventorycontains.protected voidsetCloneBackingItem(int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Clones the givenItemStackand sets in the backing array of thisInventory.protected voidsetDirectBackingItem(int slot, @Nullable org.bukkit.inventory.ItemStack itemStack) Sets theItemStackin the backing array of thisInventorywithout 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- TheInventoryto reference.itemsGetter- AFunctionwhich returns a copy of theItemStacksof theInventory.itemGetter- ABiFunctionwhich returns a copy of theItemStackon the specified slot.itemSetter- ATriConsumerwhich copies and then sets theItemStackon the specified slot.
-
-
Method Details
-
fromStorageContents
@NotNull public static @NotNull ReferencingInventory fromStorageContents(@NotNull @NotNull org.bukkit.inventory.Inventory inventory) Creates a newReferencingInventorywhich references only thestorage contentsof the specifiedInventory.- Parameters:
inventory- TheInventoryto reference.- Returns:
- The new
ReferencingInventory.
-
fromContents
@NotNull public static @NotNull ReferencingInventory fromContents(@NotNull @NotNull org.bukkit.inventory.Inventory inventory) - Parameters:
inventory- TheInventoryto reference.- Returns:
- The new
ReferencingInventory.
-
fromReversedPlayerStorageContents
@NotNull public static @NotNull ReferencingInventory fromReversedPlayerStorageContents(@NotNull @NotNull org.bukkit.inventory.PlayerInventory inventory) Creates a newReferencingInventorywith a reversed view of thePlayerInventory'sstorage contents, where the last hotbar slot is the first slot and the top left slot is the last slot.- Parameters:
inventory- ThePlayerInventoryto reference.- Returns:
- The new
ReferencingInventory.
-
getSize
public int getSize()Description copied from class:InventoryGets the size of thisInventory. -
getMaxStackSizes
public int @NotNull [] getMaxStackSizes()Description copied from class:InventoryGets the array of max stack sizes for thisInventory.- Specified by:
getMaxStackSizesin classInventory- Returns:
- The array defining the max stack sizes for this
Inventory
-
getMaxSlotStackSize
public int getMaxSlotStackSize(int slot) Description copied from class:InventoryGets the maximum stack size for a specific slot while ignoring max stack size of theItemStackon it.- Specified by:
getMaxSlotStackSizein 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:InventoryGets 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:InventoryGets 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.
- Specified by:
getUnsafeItemsin classInventory- Returns:
- The
ItemStacksthisInventorycontains.
-
getItem
@Nullable public @Nullable org.bukkit.inventory.ItemStack getItem(int slot) Description copied from class:InventoryGets 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.
-
getUnsafeItem
@Nullable public @Nullable org.bukkit.inventory.ItemStack getUnsafeItem(int slot) Description copied from class:InventoryGets 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.
- Specified by:
getUnsafeItemin classInventory- Parameters:
slot- The slot- Returns:
- The
ItemStackon the given slot.
-
setCloneBackingItem
protected void setCloneBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Description copied from class:InventoryClones 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.
- Specified by:
setCloneBackingItemin classInventory- Parameters:
slot- The slotitemStack- TheItemStackto be set
-
setDirectBackingItem
protected void setDirectBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack) Description copied from class:InventorySets 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.
- Specified by:
setDirectBackingItemin classInventory- Parameters:
slot- The slotitemStack- TheItemStackto be set
-