chat notifier: fix highlight own name matching player names with spaces

We internally rewrite nbsp to space in Player.getName(), but the in-game
drop messages which include players names still have nbsp. Modify the
generated username matcher pattern to match either nbsp or space.
This commit is contained in:
Adam
2020-04-30 14:57:53 -04:00
parent f9ad57625c
commit f60d818558
2 changed files with 42 additions and 3 deletions

View File

@@ -28,16 +28,15 @@ package net.runelite.client.plugins.chatnotifications;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.inject.Provides;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.util.regex.Pattern.quote;
import java.util.stream.Collectors;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.MessageNode;
import net.runelite.api.events.ChatMessage;
import net.runelite.client.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.client.Notifier;
import net.runelite.client.RuneLiteProperties;
@@ -45,6 +44,7 @@ import net.runelite.client.chat.ChatColorType;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.util.Text;
@@ -156,7 +156,10 @@ public class ChatNotificationsPlugin extends Plugin
if (usernameMatcher == null && client.getLocalPlayer() != null && client.getLocalPlayer().getName() != null)
{
String username = client.getLocalPlayer().getName();
usernameMatcher = Pattern.compile("\\b(" + quote(username) + ")\\b", Pattern.CASE_INSENSITIVE);
String pattern = Arrays.stream(username.split(" "))
.map(s -> s.isEmpty() ? "" : Pattern.quote(s))
.collect(Collectors.joining("[\u00a0\u0020]")); // space or nbsp
usernameMatcher = Pattern.compile("\\b" + pattern + "\\b", Pattern.CASE_INSENSITIVE);
usernameReplacer = "<col" + ChatColorType.HIGHLIGHT.name() + "><u>" + username + "</u><col" + ChatColorType.NORMAL.name() + ">";
}