diff --git a/CHANGELOG.md b/CHANGELOG.md index e826c9b1a..6ce3e5f7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ * Fixed some problems with unregistered or fake worlds * Fixed a rare concurrency issue with world saving * Fixed some contributors showing up twice +* Fixed #2062 ## Release Candidate 13 (16 Jun 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java index ef3ddea37..39f53d797 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -90,6 +91,8 @@ public interface Rechargeable extends ItemAttribute { * @return Whether the given charge could be added successfully */ default boolean addItemCharge(ItemStack item, float charge) { + Validate.isTrue(charge > 0, "Charge must be above zero!"); + if (item == null || item.getType() == Material.AIR) { throw new IllegalArgumentException("Cannot add Item charge for null or AIR"); } @@ -123,6 +126,8 @@ public interface Rechargeable extends ItemAttribute { * @return Whether the given charge could be removed successfully */ default boolean removeItemCharge(ItemStack item, float charge) { + Validate.isTrue(charge > 0, "Charge must be above zero!"); + if (item == null || item.getType() == Material.AIR) { throw new IllegalArgumentException("Cannot remove Item charge for null or AIR"); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java index 0171cdc7e..bc151084c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java @@ -51,7 +51,7 @@ public class MultiTool extends SlimefunItem implements Rechargeable { int index = selectedMode.getOrDefault(p.getUniqueId(), 0); if (!p.isSneaking()) { - if (removeItemCharge(item, -COST)) { + if (removeItemCharge(item, COST)) { SlimefunItem sfItem = modes.get(index).getItem(); if (sfItem != null) { diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestRechargeableItems.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestRechargeableItems.java index 337cda7cd..cc417f06d 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestRechargeableItems.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestRechargeableItems.java @@ -74,6 +74,9 @@ public class TestRechargeableItems { Assertions.assertThrows(IllegalArgumentException.class, () -> rechargeable.setItemCharge(item, -0.01F)); Assertions.assertThrows(IllegalArgumentException.class, () -> rechargeable.setItemCharge(item, 10.01F)); Assertions.assertThrows(IllegalArgumentException.class, () -> rechargeable.setItemCharge(item, 11)); + + Assertions.assertThrows(IllegalArgumentException.class, () -> rechargeable.addItemCharge(item, -0.1F)); + Assertions.assertThrows(IllegalArgumentException.class, () -> rechargeable.removeItemCharge(item, -0.1F)); } @Test