1
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:
Daniel Walsh 2021-01-21 19:25:38 +00:00
parent d8aaf00635
commit 549b075939
No known key found for this signature in database
GPG Key ID: 91C6D8D7C4011D82
2 changed files with 27 additions and 17 deletions

View File

@ -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.MultiTool;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.ChargingBench;
import io.github.thebusybiscuit.slimefun4.utils.RechargeableHelper;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
/**

View File

@ -1,4 +1,4 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;
package io.github.thebusybiscuit.slimefun4.utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
@ -8,6 +8,8 @@ import java.util.regex.Pattern;
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.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
@ -22,18 +24,23 @@ import net.md_5.bungee.api.ChatColor;
* interface.
*
* @author TheBusyBiscuit
* @author WalshyDev
*
* @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 Pattern REGEX = Pattern.compile(ChatColors.color("(&c&o)?" + LORE_PREFIX) + "[0-9.]+ / [0-9.]+ J");
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);
float value = decimal.floatValue();
@ -55,7 +62,9 @@ final class RechargeableHelper {
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();
Float value = meta.getPersistentDataContainer().get(key, PersistentDataType.FLOAT);