Skip to content

Commit

Permalink
Fixed an out of bounds exception when placing down storage units (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Dec 1, 2022
1 parent 3d46415 commit 6fa42d3
Showing 1 changed file with 6 additions and 4 deletions.
Expand Up @@ -27,10 +27,12 @@

public final class WStorageChest extends WChest implements StorageChest {

private static final int INVENTORY_SIZE = 5;

private final CraftWildInventory inventory;

private BigInteger amount = BigInteger.ZERO, maxAmount;
private final List<WildContainerItem> contents = new ArrayList<>(5);
private final List<WildContainerItem> contents = new ArrayList<>(INVENTORY_SIZE);
private int maxStackSize = 64;

private boolean broken = false;
Expand All @@ -39,10 +41,10 @@ public final class WStorageChest extends WChest implements StorageChest {
public WStorageChest(UUID placer, Location location, ChestData chestData) {
super(placer, location, chestData);
maxAmount = chestData.getStorageUnitMaxAmount();
inventory = plugin.getNMSInventory().createInventory(this, 5,
inventory = plugin.getNMSInventory().createInventory(this, INVENTORY_SIZE,
chestData.getTitle(1).replace("{0}", amount + ""), 0);

for (int i = 0; i < contents.size(); ++i)
for (int i = 0; i < INVENTORY_SIZE; ++i)
contents.add(WildContainerItem.AIR);

setItemStack(null);
Expand Down Expand Up @@ -296,7 +298,7 @@ public boolean onInteract(InventoryClickEvent event) {
ItemStack cursor = event.getCursor() == null ? new ItemStack(Material.AIR) : event.getCursor();
ItemStack clickedItem = event.getCurrentItem() == null ? new ItemStack(Material.AIR) : event.getCurrentItem();

if (event.getRawSlot() != 2 && event.getRawSlot() < 5) {
if (event.getRawSlot() != 2 && event.getRawSlot() < INVENTORY_SIZE) {
event.setCancelled(true);
return false;
}
Expand Down

0 comments on commit 6fa42d3

Please sign in to comment.