From ae3c05c14aeed18d934217a6c15fd27c0c7afaa7 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 4 Nov 2017 16:35:37 +0100 Subject: [PATCH] /u ncolor works! --- .../buttondevteam/chat/ChatProcessing.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index bb7c977..2022a09 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -259,21 +259,25 @@ public class ChatProcessing { val clrs = PluginMain.TownColors.get(res.getTown().getName().toLowerCase()); if (clrs == null) return player.getDisplayName(); - String ret = ""; + StringBuilder ret = new StringBuilder(); String name = ChatColor.stripColor(player.getDisplayName()); + AtomicInteger prevlen = new AtomicInteger(); BiFunction coloredNamePart = (len, i) -> "ยง" + Integer.toHexString(clrs[i].ordinal()) // 'Odds' are the last character is chopped off so we make sure to include all chars at the end - + (i + 1 == clrs.length ? name.substring(len * i) : name.substring(len * i, len * i + len)); + + (i + 1 == clrs.length ? name.substring(prevlen.get()) + : name.substring(prevlen.get(), prevlen.addAndGet(len))); int len = name.length() / clrs.length; - int[] ncl = ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations().get().stream() - .mapToInt(Integer::intValue).toArray(); - if (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length) { - System.out.println("Name length changed: " + Arrays.stream(ncl).sum() + " -> " + name.length()); + val nclar = ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations().get(); + int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray(); + if (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length) ncl = null; // Reset if name length changed + if (name.charAt(0) == '~') { // Ignore ~ in nicknames + prevlen.incrementAndGet(); + ret.append("~"); } for (int i = 0; i < clrs.length; i++) - ret += coloredNamePart.apply(ncl == null ? len : ncl[i], i); - return ret; + ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i], i)); + return ret.toString(); } catch (NotRegisteredException e) { return player.getDisplayName(); }