Skip to content

Commit

Permalink
Fix failing status bar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KonaeAkira committed Oct 1, 2022
1 parent f681ad6 commit b3a7de4
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/main/java/me/xmrvizzy/skyblocker/skyblock/StatusBarTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import java.util.regex.Pattern;

public class StatusBarTracker {
private static final Pattern STATUS_HEALTH = Pattern.compile("§[6c](\\d+)/(\\d+)❤(?:(\\+§c\\d+. *)| *)");
private static final Pattern DEFENSE_STATUS = Pattern.compile("§a(\\d+)§a❈ Defense *");
private static final Pattern MANA_USE = Pattern.compile("§b-\\d+ Mana \\\\S+(?:\\s\\S+)* *");
private static final Pattern MANA_STATUS = Pattern.compile("§b(\\d+)/(\\d+)✎ (?:Mana|§3(\\d+)ʬ) *");
private static final Pattern STATUS_HEALTH = Pattern.compile("§[6c](\\d+(,\\d\\d\\d)*)/(\\d+(,\\d\\d\\d)*)❤(?:(\\+§c(\\d+(,\\d\\d\\d)*). *)| *)");
private static final Pattern DEFENSE_STATUS = Pattern.compile("§a(\\d+(,\\d\\d\\d)*)§a❈ Defense *");
private static final Pattern MANA_USE = Pattern.compile("§b-(\\d+(,\\d\\d\\d)*) Mana \\\\S+(?:\\s\\S+)* *");
private static final Pattern MANA_STATUS = Pattern.compile("§b(\\d+(,\\d\\d\\d)*)/(\\d+(,\\d\\d\\d)*)✎ (?:Mana|§3(\\d+(,\\d\\d\\d)*)ʬ) *");

private Resource health = new Resource(100, 100, 0);
private Resource mana = new Resource(100, 100, 0);
Expand All @@ -29,19 +29,19 @@ public int getDefense() {
}

private int parseInt(Matcher m, int group) {
return Integer.parseInt(m.group(group));
return Integer.parseInt(m.group(group).replace(",", ""));
}

private void updateMana(Matcher m) {
int value = parseInt(m, 1);
int max = parseInt(m, 2);
int overflow = m.group(3) == null ? 0 : parseInt(m, 3);
int max = parseInt(m, 3);
int overflow = m.group(5) == null ? 0 : parseInt(m, 5);
this.mana = new Resource(value, max, overflow);
}

private void updateHealth(Matcher m) {
int value = parseInt(m, 1);
int max = parseInt(m, 2);
int max = parseInt(m, 3);
int overflow = 0;
ClientPlayerEntity player = null;
try {
Expand Down Expand Up @@ -70,15 +70,14 @@ private String reset(String str, Matcher m) {
}

public String update(String actionBar, boolean filterManaUse) {
actionBar = actionBar.replaceAll(",", "");
var sb = new StringBuilder();
Matcher matcher = STATUS_HEALTH.matcher(actionBar);
if (!matcher.lookingAt())
return actionBar;
updateHealth(matcher);
if (matcher.group(3) != null) {
if (matcher.group(5) != null) {
sb.append("§c❤");
sb.append(matcher.group(3));
sb.append(matcher.group(5));
}
actionBar = reset(actionBar, matcher);
if (matcher.usePattern(MANA_STATUS).lookingAt()) {
Expand Down

0 comments on commit b3a7de4

Please sign in to comment.