From 548e3586ae6ba58b5194a1b1e167eb23f7018a38 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 2 Jul 2020 11:50:07 +0200 Subject: [PATCH] Fixes #2066 --- CHANGELOG.md | 1 + .../slimefun4/core/attributes/RechargeableHelper.java | 8 +++++--- .../thebusybiscuit/slimefun4/utils/LoreBuilder.java | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba2a13b29..bde7a3959 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ * Fixed Grappling hooks making Bat sounds * Fixed #1959 * Fixed Melon Juice requiring Melons instead of Melon Slices +* Fixed #2066 ## 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/RechargeableHelper.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java index 26c1c370e..29f6c8180 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import org.bukkit.NamespacedKey; import org.bukkit.inventory.meta.ItemMeta; @@ -26,7 +27,8 @@ import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; final class RechargeableHelper { private static final NamespacedKey CHARGE_KEY = new NamespacedKey(SlimefunPlugin.instance, "item_charge"); - private static final String LORE_PREFIX = ChatColors.color("&c&o&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 RechargeableHelper() {} @@ -42,7 +44,7 @@ final class RechargeableHelper { for (int i = 0; i < lore.size(); i++) { String line = lore.get(i); - if (line.startsWith(LORE_PREFIX)) { + if (REGEX.matcher(line).matches()) { lore.set(i, LORE_PREFIX + value + " / " + capacity + " J"); meta.setLore(lore); return; @@ -66,7 +68,7 @@ final class RechargeableHelper { // If no persistent data exists, we will just fall back to the lore if (meta.hasLore()) { for (String line : meta.getLore()) { - if (line.startsWith(LORE_PREFIX) && line.contains(" / ") && line.endsWith(" J")) { + if (REGEX.matcher(line).matches()) { return Float.parseFloat(PatternUtils.SLASH_SEPARATOR.split(line)[0].replace(LORE_PREFIX, "")); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/LoreBuilder.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/LoreBuilder.java index 4ef841c4c..49d3ff06d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/LoreBuilder.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/LoreBuilder.java @@ -39,7 +39,7 @@ public final class LoreBuilder { } public static String powerCharged(int charge, int capacity) { - return "&c&o&8\u21E8 &e\u26A1 &7" + charge + " / " + capacity + " J"; + return "&8\u21E8 &e\u26A1 &7" + charge + " / " + capacity + " J"; } public static String material(String material) {