diff options
author | Yasin <LifeIsAParadox@users.noreply.github.com> | 2023-09-01 20:27:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-01 20:27:59 +0200 |
commit | 9acdbf3ebc2873a40e6d7ed1f94bc5efa71cfa92 (patch) | |
tree | 04dc866287ee477673f1e58bcaa5c4c62dca438a /src/main/java/me/xmrvizzy/skyblocker | |
parent | d41a1fd81f5bac6e3617147389f6cbcd3434cfff (diff) | |
parent | 232b0b472a7e473d1fee6b8798d21fd1bb920260 (diff) | |
download | Skyblocker-9acdbf3ebc2873a40e6d7ed1f94bc5efa71cfa92.tar.gz Skyblocker-9acdbf3ebc2873a40e6d7ed1f94bc5efa71cfa92.tar.bz2 Skyblocker-9acdbf3ebc2873a40e6d7ed1f94bc5efa71cfa92.zip |
Merge pull request #267 from msg-programs/fix-minion-widget
Fix minion widget displaying wrong info when player has 11/12 minions
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/MinionWidget.java | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/MinionWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/MinionWidget.java index 039871b2..579828d4 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/MinionWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/MinionWidget.java @@ -97,29 +97,13 @@ public class MinionWidget extends Widget { @Override public void updateContent() { - for (int i = 48; i < 59; i++) { - Matcher m = PlayerListMgr.regexAt(i, MINION_PATTERN); - if (m != null) { - - String min = m.group("name"); - String lvl = m.group("level"); - String stat = m.group("status"); - - MutableText mt = Text.literal(min + " " + lvl).append(Text.literal(": ")); - Formatting format = Formatting.RED; - if (stat.equals("ACTIVE")) { - format = Formatting.GREEN; - } else if (stat.equals("SLOW")) { - format = Formatting.YELLOW; - } - // makes "BLOCKED" also red. in reality, it's some kind of crimson - mt.append(Text.literal(stat).formatted(format)); + // this looks a bit weird because if we used regex mismatch as a stop condition, + // it'd spam the chat. + // not sure if not having that debug output is worth the cleaner solution here... - IcoTextComponent itc = new IcoTextComponent(MIN_ICOS.get(min), mt); - this.addComponent(itc); - - } else { + for (int i = 48; i < 59; i++) { + if (!this.addMinionComponent(i)) { break; } } @@ -128,8 +112,39 @@ public class MinionWidget extends Widget { // a "And X more..." text is shown // look for that and add it to the widget String more = PlayerListMgr.strAt(59); - if (more != null) { + if (more == null) { + return; + } else if (more.startsWith("And ")) { this.addComponent(new PlainTextComponent(Text.of(more))); + } else { + this.addMinionComponent(59); + } + } + + public boolean addMinionComponent(int i) { + Matcher m = PlayerListMgr.regexAt(i, MINION_PATTERN); + if (m != null) { + + String min = m.group("name"); + String lvl = m.group("level"); + String stat = m.group("status"); + + MutableText mt = Text.literal(min + " " + lvl).append(Text.literal(": ")); + + Formatting format = Formatting.RED; + if (stat.equals("ACTIVE")) { + format = Formatting.GREEN; + } else if (stat.equals("SLOW")) { + format = Formatting.YELLOW; + } + // makes "BLOCKED" also red. in reality, it's some kind of crimson + mt.append(Text.literal(stat).formatted(format)); + + IcoTextComponent itc = new IcoTextComponent(MIN_ICOS.get(min), mt); + this.addComponent(itc); + return true; + } else { + return false; } } |