From 9ff0538cf8affa00cc92714a0c851955730fe6f4 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 11 Jan 2022 21:58:39 -0500 Subject: [PATCH] chat notifications: simplify finding closing color in pattern matching Searching the replacement isn't necessary since it won't ever have any additional col tags except for the ones identified by getLastColor, which would be identified even when searching the original message. Instead, just search the original message up to and including the match. --- .../ChatNotificationsPlugin.java | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPlugin.java index 04d3e9fc8d..e0f4f174c9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPlugin.java @@ -247,7 +247,7 @@ public class ChatNotificationsPlugin extends Plugin StringBuffer stringBuffer = new StringBuffer(); do { - final int start = matcher.start(); + final int start = matcher.start(); // start not end, since username won't contain a col tag final String closeColor = MoreObjects.firstNonNull( getLastColor(message.substring(0, start)), "'); @@ -291,26 +291,16 @@ public class ChatNotificationsPlugin extends Plugin do { - String value = matcher.group(); - - // Determine the ending color by: - // 1) use the color from value if it has one - // 2) use the last color from stringBuffer + - // To do #2 we just search for the last col tag after calling appendReplacement - String endColor = getLastColor(value); - + final int end = matcher.end(); + // Determine the ending color by finding the last color tag up to and + // including the match. + final String closeColor = MoreObjects.firstNonNull( + getLastColor(nodeValue.substring(0, end)), + "'); // Strip color tags from the highlighted region so that it remains highlighted correctly - value = stripColor(value); + final String value = stripColor(matcher.group()); - matcher.appendReplacement(stringBuffer, "' + value); - - if (endColor == null) - { - endColor = getLastColor(stringBuffer.toString()); - } - - // Append end color - stringBuffer.append(endColor == null ? "" : endColor); + matcher.appendReplacement(stringBuffer, "' + value + closeColor); update = true; matchesHighlight = true;