diff options
| author | NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> | 2024-06-20 03:20:26 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-19 19:20:26 +0200 |
| commit | 289e2e4c2d5ddeca60dc604f9a0c725e07e17432 (patch) | |
| tree | 0cfde2066800d12b8802e95ea429b64d889e33dc | |
| parent | 2a3536bfb4e6c09287c2e2239c5a3b86aefd630d (diff) | |
| download | notenoughupdates-289e2e4c2d5ddeca60dc604f9a0c725e07e17432.tar.gz notenoughupdates-289e2e4c2d5ddeca60dc604f9a0c725e07e17432.tar.bz2 notenoughupdates-289e2e4c2d5ddeca60dc604f9a0c725e07e17432.zip | |
Fix Error getting name for clicking on party/guild messages to /pv (#1206)
Co-authored-by: jani270 <69345714+jani270@users.noreply.github.com>
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 1e8fb423..832b75d0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -119,6 +119,7 @@ public class Utils { EnumChatFormatting.DARK_PURPLE }; private static final Pattern CHROMA_REPLACE_PATTERN = Pattern.compile("\u00a7z(.+?)(?=\u00a7|$)"); + final static Pattern GUILD_OR_PARTY_MESSAGE_PATTERN = Pattern.compile("(?:Party|Guild|Officer) > (?:\\[.*\\] )?([a-zA-Z0-9_]+):? (?:\\[.*\\]: )?"); private static final char[] c = new char[]{'k', 'm', 'b', 't'}; private static final LerpingFloat scrollY = new LerpingFloat(0, 100); public static boolean hasEffectOverride = false; @@ -2336,18 +2337,13 @@ public class Utils { public static String getNameFromChatComponent(IChatComponent chatComponent) { String unformattedText = cleanColour(chatComponent.getSiblings().get(0).getUnformattedText()); - String username = unformattedText.substring(unformattedText.indexOf(">") + 2, unformattedText.indexOf(":")); - // If the first character is a square bracket the user has a rank - // So we get the username from the space after the closing square bracket (end of their rank) - if (username.charAt(0) == '[') { - username = username.substring(username.indexOf(" ") + 1); - } - // If we still get any square brackets it means the user was talking in guild chat with a guild rank - // So we get the username up to the space before the guild rank - if (username.contains("[") || username.contains("]")) { - username = username.substring(0, username.indexOf(" ")); - } - return username; + Matcher matcher = GUILD_OR_PARTY_MESSAGE_PATTERN.matcher(unformattedText); + if (matcher.matches()) { + return matcher.group(1); + } else { + System.out.println("[NEU] getNameFromChatComponent ERROR: " + unformattedText); + return "idk_bruh"; + } } public static void addChatMessage(@NotNull String message) { |
