From a84f34c56cdcf6646576bbf1806315c28b5ebc9c Mon Sep 17 00:00:00 2001 From: msg-programs Date: Sun, 4 Jun 2023 13:03:21 +0200 Subject: Fix IslandOwnersWidget crashing when owner is online --- .../skyblock/tabhud/widget/IslandOwnersWidget.java | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandOwnersWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandOwnersWidget.java index 1c640ed1..8550b27d 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandOwnersWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandOwnersWidget.java @@ -18,23 +18,35 @@ public class IslandOwnersWidget extends Widget { Formatting.BOLD); // matches an owner - // group 1: player name (cut off by hypixel for some reason) - // group 2: last seem - // TODO: test with owner online - private static final Pattern OWNER_PATTERN = Pattern.compile("(?.*) \\((?.*)\\)"); + // group 1: player name + // group 2: last seen, if owner not online + private static final Pattern OWNER_PATTERN = Pattern + .compile("^(?.*) \\((?.*)?\\)$|^\\[\\d*\\] (?.*)$"); public IslandOwnersWidget() { super(TITLE, Formatting.DARK_PURPLE.getColorValue()); for (int i = 1; i < 20; i++) { - Matcher m = PlayerListMgr.regexAt( i, OWNER_PATTERN); + Matcher m = PlayerListMgr.regexAt(i, OWNER_PATTERN); if (m == null) { break; } - Text entry = Text.literal(m.group("name")) + String name = null, lastseen = null; + Formatting format = null; + if (m.group("nameA") != null) { + name = m.group("nameA"); + lastseen = m.group("lastseen"); + format = Formatting.GRAY; + } else { + name = m.group("nameB"); + lastseen = "Online"; + format = Formatting.WHITE; + } + + Text entry = Text.literal(name) .append( - Text.literal(" (" + m.group("lastseen") + ")") - .formatted(Formatting.GRAY)); + Text.literal(" (" + lastseen + ")") + .formatted(format)); PlainTextComponent ptc = new PlainTextComponent(entry); this.addComponent(ptc); } -- cgit