Class VirtualInventory
Inventory implementation that is identified by a UUID and backed by a simple ItemStack array.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionVirtualInventory(int size) Constructs a newVirtualInventoryVirtualInventory(int @NotNull [] maxStackSizes) Constructs a newVirtualInventoryVirtualInventory(int size, @Nullable org.bukkit.inventory.ItemStack @Nullable [] items, int @Nullable [] maxStackSizes) Constructs a newVirtualInventoryVirtualInventory(@Nullable UUID uuid, int size) Constructs a newVirtualInventoryVirtualInventory(@Nullable UUID uuid, int @NotNull [] maxStackSizes) Constructs a newVirtualInventoryVirtualInventory(@Nullable UUID uuid, int size, @Nullable org.bukkit.inventory.ItemStack @Nullable [] items, int @Nullable [] maxStackSizes) Constructs a newVirtualInventoryVirtualInventory(@Nullable UUID uuid, @Nullable org.bukkit.inventory.ItemStack @NotNull [] items) Constructs a newVirtualInventoryVirtualInventory(@Nullable UUID uuid, @Nullable org.bukkit.inventory.ItemStack @NotNull [] items, int @Nullable [] maxStackSizes) Constructs a newVirtualInventoryVirtualInventory(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) Constructs a newVirtualInventoryVirtualInventory(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items, int @Nullable [] maxStackSizes) Constructs a newVirtualInventoryVirtualInventory(VirtualInventory inventory) Creates a copy of the givenVirtualInventory. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddResizeHandler(@NotNull BiConsumer<@NotNull Integer, @NotNull Integer> resizeHandler) Adds a handler that is called every time thisVirtualInventoryis resized.static VirtualInventorydeserialize(byte[] bytes) Deserializes aVirtualInventoryfrom a byte array.static VirtualInventoryDeserializes aVirtualInventoryfrom anInputStream.@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.@Nullable List<@NotNull BiConsumer<@NotNull Integer, @NotNull Integer>> Gets the handlers that are called every time thisVirtualInventoryis resized.intgetSize()Gets the size of thisInventory.org.bukkit.inventory.ItemStackgetUnsafeItem(int slot) Gets theItemStackon that slot.@Nullable org.bukkit.inventory.ItemStack @NotNull []Gets theItemStacksthisInventorycontains.@NotNull UUIDgetUuid()Gets theUUIDof thisVirtualInventory.voidremoveResizeHandler(@NotNull BiConsumer<@NotNull Integer, @NotNull Integer> resizeHandler) Removes a handler that is called every time thisVirtualInventoryis resized.voidresize(int size) Changes the size of theVirtualInventory.byte[]Serializes thisVirtualInventoryto a byte array.voidserialize(OutputStream out) Serializes thisVirtualInventoryto anOutputStream.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.voidsetMaxStackSize(int slot, int maxStackSize) Sets the maximum allowed stack size on a specific slot.voidsetMaxStackSizes(int @NotNull [] stackSizes) Sets the array of max stack sizes for thisInventory.voidsetResizeHandlers(@Nullable List<@NotNull BiConsumer<@NotNull Integer, @NotNull Integer>> resizeHandlers) Sets the handlers that are called every time thisVirtualInventoryis resized.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
-
Constructor Details
-
VirtualInventory
public VirtualInventory(@Nullable @Nullable UUID uuid, int size, @Nullable @Nullable org.bukkit.inventory.ItemStack @Nullable [] items, int @Nullable [] maxStackSizes) Constructs a newVirtualInventory- Parameters:
uuid- TheUUIDof thisVirtualInventory. Can be null, only used for serialization.size- The amount of slots thisVirtualInventoryhas.items- A predefined array of content. Can be null. Will not get copied!maxStackSizes- An array of maximum allowed stack sizes for each slot in theVirtualInventory. Can be null for 64.- Throws:
IllegalArgumentException- If the given size does not match the length of the items array or the length of the stackSizes array.IllegalArgumentException- If the items array contains airItemStacks.
-
VirtualInventory
public VirtualInventory(int size, @Nullable @Nullable org.bukkit.inventory.ItemStack @Nullable [] items, int @Nullable [] maxStackSizes) Constructs a newVirtualInventory- Parameters:
size- The amount of slots thisVirtualInventoryhas.items- A predefined array of content. Can be null. Will not get copied!maxStackSizes- An array of maximum allowed stack sizes for each slot in theVirtualInventory. Can be null for 64.
-
VirtualInventory
public VirtualInventory(@Nullable @Nullable UUID uuid, @Nullable @Nullable org.bukkit.inventory.ItemStack @NotNull [] items, int @Nullable [] maxStackSizes) Constructs a newVirtualInventory- Parameters:
uuid- TheUUIDof thisVirtualInventory. Can be null, only used for serialization.items- A predefined array of content. Will not get copied!maxStackSizes- An array of maximum allowed stack sizes for each slot in theVirtualInventory. Can be null for 64.
-
VirtualInventory
public VirtualInventory(@Nullable @Nullable org.bukkit.inventory.ItemStack @NotNull [] items, int @Nullable [] maxStackSizes) Constructs a newVirtualInventory- Parameters:
items- A predefined array of content. Will not get copied!maxStackSizes- An array of maximum allowed stack sizes for each slot in theVirtualInventory. Can be null for 64.
-
VirtualInventory
public VirtualInventory(@Nullable @Nullable UUID uuid, @Nullable @Nullable org.bukkit.inventory.ItemStack @NotNull [] items) Constructs a newVirtualInventory- Parameters:
uuid- TheUUIDof thisVirtualInventory. Can be null, only used for serialization.items- A predefined array of content. Will not get copied!
-
VirtualInventory
public VirtualInventory(@Nullable @Nullable org.bukkit.inventory.ItemStack @NotNull [] items) Constructs a newVirtualInventory- Parameters:
items- A predefined array of content. Will not get copied!
-
VirtualInventory
Constructs a newVirtualInventory- Parameters:
uuid- TheUUIDof thisVirtualInventory. Can be null, only used for serialization.maxStackSizes- An array of maximum allowed stack sizes for each slot in theVirtualInventory.
-
VirtualInventory
public VirtualInventory(int @NotNull [] maxStackSizes) Constructs a newVirtualInventory- Parameters:
maxStackSizes- An array of maximum allowed stack sizes for each slot in theVirtualInventory.
-
VirtualInventory
Constructs a newVirtualInventory- Parameters:
uuid- TheUUIDof thisVirtualInventory. Can be null, only used for serialization.size- The amount of slots thisVirtualInventoryhas.
-
VirtualInventory
public VirtualInventory(int size) Constructs a newVirtualInventory- Parameters:
size- The amount of slots thisVirtualInventoryhas.
-
VirtualInventory
Creates a copy of the givenVirtualInventory.- Parameters:
inventory- TheVirtualInventoryto copy.
-
-
Method Details
-
deserialize
Deserializes aVirtualInventoryfrom a byte array.- Parameters:
bytes- The byte array to deserialize from.- Returns:
- The deserialized
VirtualInventory.
-
deserialize
Deserializes aVirtualInventoryfrom anInputStream.- Parameters:
in- TheInputStreamto deserialize from.- Returns:
- The deserialized
VirtualInventory.
-
serialize
public byte[] serialize()Serializes thisVirtualInventoryto a byte array.This method only serializes the
UUIDandItemStacks.- Returns:
- The serialized data.
-
serialize
Serializes thisVirtualInventoryto anOutputStream.This method only serializes the
UUIDandItemStacks.- Parameters:
out- TheOutputStreamto write serialized data to.
-
setResizeHandlers
public void setResizeHandlers(@Nullable @Nullable List<@NotNull BiConsumer<@NotNull Integer, @NotNull Integer>> resizeHandlers) Sets the handlers that are called every time thisVirtualInventoryis resized.- Parameters:
resizeHandlers- The handlers to set.
-
getResizeHandlers
@Nullable public @Nullable List<@NotNull BiConsumer<@NotNull Integer,@NotNull Integer>> getResizeHandlers()Gets the handlers that are called every time thisVirtualInventoryis resized.- Returns:
- The handlers.
-
addResizeHandler
public void addResizeHandler(@NotNull @NotNull BiConsumer<@NotNull Integer, @NotNull Integer> resizeHandler) Adds a handler that is called every time thisVirtualInventoryis resized.- Parameters:
resizeHandler- The handler to add.
-
removeResizeHandler
public void removeResizeHandler(@NotNull @NotNull BiConsumer<@NotNull Integer, @NotNull Integer> resizeHandler) Removes a handler that is called every time thisVirtualInventoryis resized.- Parameters:
resizeHandler- The handler to remove.
-
resize
public void resize(int size) Changes the size of theVirtualInventory.ItemStacksin slots which are no longer valid will be removed from theVirtualInventory. This method does not call an event.- Parameters:
size- The new size of theVirtualInventory
-
setMaxStackSizes
public void setMaxStackSizes(int @NotNull [] stackSizes) Sets the array of max stack sizes for thisInventory.- Parameters:
stackSizes- The array defining the max stack sizes for thisInventory.
-
setMaxStackSize
public void setMaxStackSize(int slot, int maxStackSize) Sets the maximum allowed stack size on a specific slot.- Parameters:
slot- The slotmaxStackSize- The max stack size
-
getUuid
Gets theUUIDof thisVirtualInventory.- Returns:
- The
UUIDof thisVirtualInventory.
-
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
public 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
-