mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2062
This commit is contained in:
parent
492010a8d4
commit
03c08ed6f1
@ -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
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user