diff --git a/src/main/java/net/theevilreaper/aves/inventory/layout/InventoryLayoutImpl.java b/src/main/java/net/theevilreaper/aves/inventory/layout/InventoryLayoutImpl.java index d3093a4d..e24a4f48 100644 --- a/src/main/java/net/theevilreaper/aves/inventory/layout/InventoryLayoutImpl.java +++ b/src/main/java/net/theevilreaper/aves/inventory/layout/InventoryLayoutImpl.java @@ -100,7 +100,7 @@ public void applyLayout(ItemStack[] itemStacks, @Nullable Locale locale) { */ @Override public InventoryLayoutImpl setItem(int slot, ItemStack.Builder itemBuilder, @Nullable InventoryClick clickEvent) { - Check.argCondition(slot < 0 || slot > contents.length, INDEX_ERROR); + Check.argCondition(slot < 0 || slot >= contents.length, INDEX_ERROR); this.contents[slot] = new InventorySlot(itemBuilder, clickEvent); return this; } @@ -110,7 +110,7 @@ public InventoryLayoutImpl setItem(int slot, ItemStack.Builder itemBuilder, @Nul */ @Override public InventoryLayoutImpl setItem(int slot, ItemStack itemStack, @Nullable InventoryClick clickEvent) { - Check.argCondition(slot < 0 || slot > contents.length, INDEX_ERROR); + Check.argCondition(slot < 0 || slot >= contents.length, INDEX_ERROR); this.contents[slot] = new InventorySlot(itemStack, clickEvent); return this; } @@ -120,7 +120,7 @@ public InventoryLayoutImpl setItem(int slot, ItemStack itemStack, @Nullable Inve */ @Override public InventoryLayoutImpl setItem(int slot, ISlot iSlot, InventoryClick clickEvent) { - Check.argCondition(slot < 0 || slot > contents.length, INDEX_ERROR); + Check.argCondition(slot < 0 || slot >= contents.length, INDEX_ERROR); iSlot.setClick(clickEvent); contents[slot] = iSlot; return this; @@ -131,7 +131,7 @@ public InventoryLayoutImpl setItem(int slot, ISlot iSlot, InventoryClick clickEv */ @Override public InventoryLayoutImpl setItem(int slot, ISlot slotItem) { - Check.argCondition(slot < 0 || slot > contents.length, INDEX_ERROR); + Check.argCondition(slot < 0 || slot >= contents.length, INDEX_ERROR); contents[slot] = slotItem; return this; } @@ -141,7 +141,7 @@ public InventoryLayoutImpl setItem(int slot, ISlot slotItem) { */ @Override public InventoryLayoutImpl blank(int slot) { - Check.argCondition(slot < 0 || slot > contents.length, INDEX_ERROR); + Check.argCondition(slot < 0 || slot >= contents.length, INDEX_ERROR); this.contents[slot] = BLANK_SLOT; return this; } @@ -151,7 +151,7 @@ public InventoryLayoutImpl blank(int slot) { */ @Override public InventoryLayoutImpl clear(int slot) { - Check.argCondition(slot < 0 || slot > contents.length, INDEX_ERROR); + Check.argCondition(slot < 0 || slot >= contents.length, INDEX_ERROR); contents[slot] = BLANK_SLOT; return this; } @@ -161,7 +161,7 @@ public InventoryLayoutImpl clear(int slot) { */ @Override public InventoryLayoutImpl update(int index, @Nullable InventoryClick listener) { - Check.argCondition(index < 0 || index > contents.length, INDEX_ERROR); + Check.argCondition(index < 0 || index >= contents.length, INDEX_ERROR); contents[index].setClick(listener == null ? CANCEL_CLICK : listener); return this; } @@ -171,7 +171,7 @@ public InventoryLayoutImpl update(int index, @Nullable InventoryClick listener) */ @Override public InventoryLayoutImpl update(int index, @Nullable ItemStack stack) { - Check.argCondition(index < 0 || index > contents.length, INDEX_ERROR); + Check.argCondition(index < 0 || index >= contents.length, INDEX_ERROR); contents[index].setItemStack(stack); return this; } @@ -181,7 +181,7 @@ public InventoryLayoutImpl update(int index, @Nullable ItemStack stack) { */ @Override public InventoryLayoutImpl update(int index, ItemStack stack, @Nullable InventoryClick click) { - Check.argCondition(index < 0 || index > contents.length, INDEX_ERROR); + Check.argCondition(index < 0 || index >= contents.length, INDEX_ERROR); var slot = contents[index]; slot.setItemStack(stack); slot.setClick(click == null ? CANCEL_CLICK : click); @@ -193,7 +193,7 @@ public InventoryLayoutImpl update(int index, ItemStack stack, @Nullable Inventor */ @Override public InventoryLayout remove(int index) { - Check.argCondition(index < 0 || index > this.contents.length, + Check.argCondition(index < 0 || index >= this.contents.length, "The given index does not fit into the array (0, " + this.contents.length + ")"); this.contents[index] = BLANK_SLOT; return this; diff --git a/src/test/java/net/theevilreaper/aves/inventory/InventoryLayoutTest.java b/src/test/java/net/theevilreaper/aves/inventory/InventoryLayoutTest.java index dc40e5dd..d40ec7ff 100644 --- a/src/test/java/net/theevilreaper/aves/inventory/InventoryLayoutTest.java +++ b/src/test/java/net/theevilreaper/aves/inventory/InventoryLayoutTest.java @@ -187,6 +187,13 @@ void failItemSet() { catchError(IllegalArgumentException.class, () -> layout.setItem(-1, slot)); catchError(IllegalArgumentException.class, () -> layout.setItem(100, slot)); + + int exactSize = layout.getSize(); + catchError(IllegalArgumentException.class, () -> layout.setItem(exactSize, ItemStack.of(Material.PAPER))); + catchError(IllegalArgumentException.class, () -> layout.setItem(exactSize, slot)); + catchError(IllegalArgumentException.class, () -> layout.blank(exactSize)); + catchError(IllegalArgumentException.class, () -> layout.clear(exactSize)); + catchError(IllegalArgumentException.class, () -> layout.remove(exactSize)); } @Test