From a3b3af859a3883b0a06ecb9d1aa2b54855085787 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 16 Dec 2016 21:25:13 +0100 Subject: [PATCH] Properly added a bug as a feature Wth did I just do before - Anyways, fixed null nicknames --- src/main/java/buttondevteam/chat/ChatProcessing.java | 10 ++++++++-- .../buttondevteam/chat/formatting/ChatFormatter.java | 9 +++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 238d28a..4ff2106 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -122,11 +122,17 @@ public class ChatProcessing { namesb.append(")"); StringBuilder nicksb = new StringBuilder(); nicksb.append("(?i)("); - for (Player p : PluginMain.GetPlayers()) - nicksb.append(PlayerListener.nicknames.inverse().get(p.getUniqueId())).append("|"); + for (Player p : PluginMain.GetPlayers()) { + final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId()); + if (nick != null) // Not everyone has a nickname + nicksb.append(nick).append("|"); + } nicksb.deleteCharAt(nicksb.length() - 1); nicksb.append(")"); + formatters + .add(new ChatFormatterBuilder().setRegex(Pattern.compile("null")).setColor(Color.DarkRed).build()); // Properly added a bug as a feature + formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(namesb.toString())).setColor(Color.Aqua) .setOnmatch((String match) -> { Player p = Bukkit.getPlayer(match); diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java index 762bc11..0594c93 100644 --- a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java +++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java @@ -164,15 +164,12 @@ public final class ChatFormatter { section.Formatters.sort((cf2, cf1) -> cf1.priority.compareTo(cf2.priority)); for (ChatFormatter formatter : section.Formatters) { DebugCommand.SendDebugMessage("Applying formatter: " + formatter); - if (formatter.onmatch != null) { - String f = formatter.onmatch.apply(originaltext); - if (f != null) - originaltext = f; //TODO: Find out... - } + if (formatter.onmatch != null) + originaltext = formatter.onmatch.apply(originaltext); if (formatter.color != null) color = formatter.color; if (formatter.format != null) - format = formatter.format.getFlag(); // TODO: Fix + format = formatter.format.getFlag(); //TODO: Fix if (formatter.openlink != null) openlink = formatter.openlink; }