diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChargeUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChargeUtils.java index dffd055d53..ee22668eee 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChargeUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChargeUtils.java @@ -29,8 +29,9 @@ public final class ChargeUtils { private static final String LORE_PREFIX = ChatColors.color("&8\u21E8 &e\u26A1 &7"); + private static final String NUMBER_PREFIX = "([+-]?[\\d]+([\\.][\\d]+)?([Ee][+-]?[\\d]+)?)"; private static final Pattern REGEX = - Pattern.compile(ChatColors.color("(&c&o)?" + LORE_PREFIX) + "[0-9.]+ / [0-9.]+ J"); + Pattern.compile(ChatColors.color("(&c&o)?" + LORE_PREFIX) + NUMBER_PREFIX + " / " + NUMBER_PREFIX + " J"); private ChargeUtils() {} @@ -76,9 +77,9 @@ public static float getCharge(@Nonnull ItemMeta meta) { // If no persistent data exists, we will just fall back to the lore if (meta.hasLore()) { for (String line : meta.getLore()) { - if (REGEX.matcher(line).matches()) { - String data = - ChatColor.stripColor(PatternUtils.SLASH_SEPARATOR.split(line)[0].replace(LORE_PREFIX, "")); + var matcher = REGEX.matcher(line); + if (matcher.matches()) { + String data = matcher.group(2); float loreValue = Float.parseFloat(data); container.set(key, PersistentDataType.FLOAT, loreValue);