VirtualInventory#canHold with list parameter

This commit is contained in:
NichtStudioCode 2021-07-11 13:09:25 +02:00
parent 18d948b03f
commit 2be6a60022

@ -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. * 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) { public int[] simulateAdd(@NotNull List<@NotNull ItemStack> itemStacks) {
if (itemStacks.isEmpty()) return new int[] {};
if (itemStacks.size() == 1) { if (itemStacks.size() == 1) {
return new int[] {simulateSingleAdd(itemStacks.get(0))}; return new int[] {simulateSingleAdd(itemStacks.get(0))};
} else { } 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. * Returns the amount of items that wouldn't fit in the inventory when added.
* <br> * <br>