mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Make RechargeableHelper public
This commit is contained in:
parent
d8aaf00635
commit
549b075939
@ -9,6 +9,7 @@ import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNet;
|
|||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Jetpack;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Jetpack;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.MultiTool;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.MultiTool;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.ChargingBench;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.ChargingBench;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.utils.RechargeableHelper;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.core.attributes;
|
package io.github.thebusybiscuit.slimefun4.utils;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
@ -8,6 +8,8 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
@ -22,18 +24,23 @@ import net.md_5.bungee.api.ChatColor;
|
|||||||
* interface.
|
* interface.
|
||||||
*
|
*
|
||||||
* @author TheBusyBiscuit
|
* @author TheBusyBiscuit
|
||||||
|
* @author WalshyDev
|
||||||
*
|
*
|
||||||
* @see Rechargeable
|
* @see Rechargeable
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
final class RechargeableHelper {
|
public final class RechargeableHelper {
|
||||||
|
|
||||||
private static final String LORE_PREFIX = ChatColors.color("&8\u21E8 &e\u26A1 &7");
|
private static final String LORE_PREFIX = ChatColors.color("&8\u21E8 &e\u26A1 &7");
|
||||||
private static final Pattern REGEX = Pattern.compile(ChatColors.color("(&c&o)?" + LORE_PREFIX) + "[0-9.]+ / [0-9.]+ J");
|
private static final Pattern REGEX = Pattern.compile(ChatColors.color("(&c&o)?" + LORE_PREFIX) + "[0-9.]+ / [0-9.]+ J");
|
||||||
|
|
||||||
private RechargeableHelper() {}
|
private RechargeableHelper() {}
|
||||||
|
|
||||||
static void setCharge(@Nonnull ItemMeta meta, float charge, float capacity) {
|
public static void setCharge(@Nonnull ItemMeta meta, float charge, float capacity) {
|
||||||
|
Validate.notNull(meta, "Meta cannot be null!");
|
||||||
|
Validate.isTrue(charge >= 0, "Charge has to be equal to or greater than 0!");
|
||||||
|
Validate.isTrue(charge <= capacity, "Charge must be less than the capacity!");
|
||||||
|
|
||||||
BigDecimal decimal = BigDecimal.valueOf(charge).setScale(2, RoundingMode.HALF_UP);
|
BigDecimal decimal = BigDecimal.valueOf(charge).setScale(2, RoundingMode.HALF_UP);
|
||||||
float value = decimal.floatValue();
|
float value = decimal.floatValue();
|
||||||
|
|
||||||
@ -55,7 +62,9 @@ final class RechargeableHelper {
|
|||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float getCharge(@Nonnull ItemMeta meta) {
|
public static float getCharge(@Nonnull ItemMeta meta) {
|
||||||
|
Validate.notNull(meta, "Meta cannot be null!");
|
||||||
|
|
||||||
NamespacedKey key = SlimefunPlugin.getRegistry().getItemChargeDataKey();
|
NamespacedKey key = SlimefunPlugin.getRegistry().getItemChargeDataKey();
|
||||||
Float value = meta.getPersistentDataContainer().get(key, PersistentDataType.FLOAT);
|
Float value = meta.getPersistentDataContainer().get(key, PersistentDataType.FLOAT);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user