Skip to content

Commit 5c2ad07

Browse files
Fix nullability in VirtualInventoryManager
1 parent e78a70b commit 5c2ad07

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

invui/src/main/java/xyz/xenondevs/invui/inventory/VirtualInventoryManager.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ public VirtualInventory createNew(UUID uuid, int size) {
6060
* @param uuid The UUID of the {@link VirtualInventory}.
6161
* @param size The size of the {@link VirtualInventory}.
6262
* @param items The items of the {@link VirtualInventory}.
63+
* Can be null for an empty inventory.
6364
* @param maxStackSizes The max stack sizes of the {@link VirtualInventory}.
65+
* Can be null for the default stack size of 64.
6466
* @return The created {@link VirtualInventory}.
6567
* @throws IllegalArgumentException If a {@link VirtualInventory} with the given UUID already exists.
6668
*/
67-
public VirtualInventory createNew(UUID uuid, int size, ItemStack[] items, int[] maxStackSizes) {
69+
public VirtualInventory createNew(UUID uuid, int size, @Nullable ItemStack @Nullable [] items, int @Nullable [] maxStackSizes) {
6870
if (inventories.containsKey(uuid))
6971
throw new IllegalArgumentException("A Virtual Inventory with that UUID already exists");
7072

@@ -103,13 +105,17 @@ public VirtualInventory getOrCreate(UUID uuid, int size) {
103105
* @param uuid The UUID of the {@link VirtualInventory}.
104106
* @param size The size of the {@link VirtualInventory} to create if no such inventory exists.
105107
* @param items The items of the {@link VirtualInventory} to create if no such inventory exists.
108+
* Can be null for an empty inventory.
106109
* @param maxStackSizes The max stack sizes of the {@link VirtualInventory}.
110+
* Can be null for the default stack size of 64.
107111
* @return The {@link VirtualInventory} with the given UUID or a new one with the given size, items and stack sizes if no such inventory exists.
108112
*/
109-
public VirtualInventory getOrCreate(UUID uuid, int size, ItemStack[] items, int[] maxStackSizes) {
113+
public VirtualInventory getOrCreate(UUID uuid, int size, @Nullable ItemStack @Nullable [] items, int @Nullable [] maxStackSizes) {
110114
VirtualInventory inventory = getByUuid(uuid);
111115
if (inventory != null) {
112-
inventory.setMaxStackSizes(ArrayUtils.copyOf(maxStackSizes, inventory.size, 64));
116+
if (maxStackSizes != null) {
117+
inventory.setMaxStackSizes(ArrayUtils.copyOf(maxStackSizes, inventory.size, 64));
118+
}
113119
return inventory;
114120
} else {
115121
return createNew(uuid, size, items, maxStackSizes);

0 commit comments

Comments
 (0)