Skip to content

Commit

Permalink
Update ChargeUtils.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Nov 16, 2024
2 parents 36d39bc + e45c93a commit b660729
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
*/
public final class ChargeUtils {
private static final String LORE_PREFIX = "§8\u21E8 §e\u26A1 §7";
private static final String NUMBER_PREFIX = "([+-]?\\d+([.]\\d+)?([Ee][+-]?\\d+)?)";
private static final Pattern REGEX =
Pattern.compile(LORE_PREFIX + "[0-9.]+ / [0-9.]+ J", Pattern.CASE_INSENSITIVE);
Pattern.compile(LORE_PREFIX + NUMBER_PREFIX + " / " + NUMBER_PREFIX + " J", Pattern.CASE_INSENSITIVE);


private static final Pattern REGEX_NEW =
Pattern.compile("[0-9.]+ / [0-9.]+ J");
Pattern.compile(NUMBER_PREFIX + "/" + NUMBER_PREFIX + " J");

private ChargeUtils() {
}
Expand Down Expand Up @@ -104,10 +107,9 @@ public static float getCharge(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 =
TextUtils.toPlainText(PatternUtils.SLASH_SEPARATOR.split(line)[0]
.toLowerCase().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 b660729

Please sign in to comment.