From 2be6a60022d4a2f945830723f04b40ee4c0920bb Mon Sep 17 00:00:00 2001 From: NichtStudioCode <51272202+NichtStudioCode@users.noreply.github.com> Date: Sun, 11 Jul 2021 13:09:25 +0200 Subject: [PATCH] VirtualInventory#canHold with list parameter --- .../virtualinventory/VirtualInventory.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/InvUI/src/main/java/de/studiocode/invui/virtualinventory/VirtualInventory.java b/InvUI/src/main/java/de/studiocode/invui/virtualinventory/VirtualInventory.java index f952cc8..134f8b9 100644 --- a/InvUI/src/main/java/de/studiocode/invui/virtualinventory/VirtualInventory.java +++ b/InvUI/src/main/java/de/studiocode/invui/virtualinventory/VirtualInventory.java @@ -536,6 +536,8 @@ public class VirtualInventory implements ConfigurationSerializable { * The size of this array is always equal to the amount of {@link ItemStack}s provided as method parameters. */ public int[] simulateAdd(@NotNull List<@NotNull ItemStack> itemStacks) { + if (itemStacks.isEmpty()) return new int[] {}; + if (itemStacks.size() == 1) { return new int[] {simulateSingleAdd(itemStacks.get(0))}; } else { @@ -558,6 +560,22 @@ public class VirtualInventory implements ConfigurationSerializable { } } + /** + * Simulates adding {@link ItemStack}s to this {@link VirtualInventory} + * and then returns if all {@link ItemStack}s would fit. + * + * @return If all provided {@link ItemStack}s would fit if added. + */ + public boolean canHold(@NotNull List<@NotNull ItemStack> itemStacks) { + if (itemStacks.isEmpty()) return true; + + if (itemStacks.size() == 1) { + return simulateSingleAdd(itemStacks.get(0)) == 0; + } else { + return Arrays.stream(simulateMultiAdd(itemStacks)).allMatch(i -> i == 0); + } + } + /** * Returns the amount of items that wouldn't fit in the inventory when added. *