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
This commit is contained in:
@@ -243,12 +243,24 @@ public class ChatNotificationsPlugin extends Plugin
|
|||||||
Matcher matcher = usernameMatcher.matcher(message);
|
Matcher matcher = usernameMatcher.matcher(message);
|
||||||
if (matcher.find())
|
if (matcher.find())
|
||||||
{
|
{
|
||||||
final int start = matcher.start();
|
|
||||||
final String username = client.getLocalPlayer().getName();
|
final String username = client.getLocalPlayer().getName();
|
||||||
final String closeColor = MoreObjects.firstNonNull(getLastColor(message.substring(0, start)), "<col" + ChatColorType.NORMAL + '>');
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
final String replacement = "<col" + ChatColorType.HIGHLIGHT.name() + "><u>" + username + "</u>" + closeColor;
|
do
|
||||||
messageNode.setValue(matcher.replaceAll(replacement));
|
{
|
||||||
|
final int start = matcher.start();
|
||||||
|
final String closeColor = MoreObjects.firstNonNull(
|
||||||
|
getLastColor(message.substring(0, start)),
|
||||||
|
"<col" + ChatColorType.NORMAL + '>');
|
||||||
|
final String replacement = "<col" + ChatColorType.HIGHLIGHT.name() + "><u>" + username + "</u>" + closeColor;
|
||||||
|
matcher.appendReplacement(stringBuffer, replacement);
|
||||||
|
}
|
||||||
|
while (matcher.find());
|
||||||
|
|
||||||
|
matcher.appendTail(stringBuffer);
|
||||||
|
|
||||||
|
messageNode.setValue(stringBuffer.toString());
|
||||||
update = true;
|
update = true;
|
||||||
|
|
||||||
if (config.notifyOnOwnName() && (chatMessage.getType() == ChatMessageType.PUBLICCHAT
|
if (config.notifyOnOwnName() && (chatMessage.getType() == ChatMessageType.PUBLICCHAT
|
||||||
|| chatMessage.getType() == ChatMessageType.PRIVATECHAT
|
|| chatMessage.getType() == ChatMessageType.PRIVATECHAT
|
||||||
|| chatMessage.getType() == ChatMessageType.FRIENDSCHAT
|
|| chatMessage.getType() == ChatMessageType.FRIENDSCHAT
|
||||||
|
|||||||
Reference in New Issue
Block a user