Skip to content

Commit

Permalink
fix(util): update regex to match sci number (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Nov 16, 2024
1 parent 6d63b3c commit 2cd2c6e
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2cd2c6e

Please sign in to comment.