From c7e6ffb4de22f687bcdf1f1d3db2bb3bd7bc9d6e Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 11 Jan 2022 21:30:18 -0500 Subject: [PATCH] chat notifications: fix restoring last color on own name highlight This was an issue with multiple name matches, since it was applying the replacement with its close color to all matches, even though only scanning the message for the last color up until the first match --- .../ChatNotificationsPlugin.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 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 e275efc076..04d3e9fc8d 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 @@ -243,12 +243,24 @@ public class ChatNotificationsPlugin extends Plugin Matcher matcher = usernameMatcher.matcher(message); if (matcher.find()) { - final int start = matcher.start(); final String username = client.getLocalPlayer().getName(); - final String closeColor = MoreObjects.firstNonNull(getLastColor(message.substring(0, start)), "'); - final String replacement = "" + username + "" + closeColor; - messageNode.setValue(matcher.replaceAll(replacement)); + StringBuffer stringBuffer = new StringBuffer(); + do + { + final int start = matcher.start(); + final String closeColor = MoreObjects.firstNonNull( + getLastColor(message.substring(0, start)), + "'); + final String replacement = "" + username + "" + closeColor; + matcher.appendReplacement(stringBuffer, replacement); + } + while (matcher.find()); + + matcher.appendTail(stringBuffer); + + messageNode.setValue(stringBuffer.toString()); update = true; + if (config.notifyOnOwnName() && (chatMessage.getType() == ChatMessageType.PUBLICCHAT || chatMessage.getType() == ChatMessageType.PRIVATECHAT || chatMessage.getType() == ChatMessageType.FRIENDSCHAT