From ea5e7ae87d6ed622dc49fcc8af37b1d4647df1b2 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 25 Jun 2016 21:05:00 +0200 Subject: [PATCH] Chat formatter WIP --- .../norbipeti/thebuttonmcchat/Channel.java | 19 +-- .../thebuttonmcchat/ChatProcessing.java | 113 +++++------------- .../thebuttonmcchat/MaybeOfflinePlayer.java | 2 +- .../commands/ucmds/CCommand.java | 8 ++ 4 files changed, 53 insertions(+), 89 deletions(-) diff --git a/src/io/github/norbipeti/thebuttonmcchat/Channel.java b/src/io/github/norbipeti/thebuttonmcchat/Channel.java index ad6dcb1..b7264f0 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/Channel.java +++ b/src/io/github/norbipeti/thebuttonmcchat/Channel.java @@ -2,18 +2,23 @@ package io.github.norbipeti.thebuttonmcchat; public class Channel { public final String DisplayName; - public final String Color; + public final ChatFormatter.Color Color; public final String Command; - public Channel(String displayname, String color, String command) { + public Channel(String displayname, ChatFormatter.Color color, String command) { DisplayName = displayname; Color = color; Command = command; } - public static Channel GlobalChat = new Channel("§fg§f", "white", "g"); - public static Channel TownChat = new Channel("§3TC§f", "dark_aqua", "tc"); - public static Channel NationChat = new Channel("§6NC§f", "gold", "nc"); - public static Channel AdminChat = new Channel("§cADMIN§f", "red", "a"); - public static Channel ModChat = new Channel("§9MOD§f", "blue", "mod"); + public static Channel GlobalChat = new Channel("§fg§f", + ChatFormatter.Color.White, "g"); + public static Channel TownChat = new Channel("§3TC§f", + ChatFormatter.Color.DarkAqua, "tc"); + public static Channel NationChat = new Channel("§6NC§f", + ChatFormatter.Color.Gold, "nc"); + public static Channel AdminChat = new Channel("§cADMIN§f", + ChatFormatter.Color.Red, "a"); + public static Channel ModChat = new Channel("§9MOD§f", + ChatFormatter.Color.Blue, "mod"); } diff --git a/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java b/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java index 707b3f2..57b5ee5 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java +++ b/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java @@ -61,101 +61,52 @@ public class ChatProcessing { Channel currentchannel = (mp == null ? PlayerListener.ConsoleChannel : mp.CurrentChannel); - String colormode = currentchannel.Color; - if (mp != null && mp.OtherColorMode.length() > 0) + ArrayList formatters = new ArrayList(); + + ChatFormatter.Color colormode = currentchannel.Color; + if (mp != null && mp.OtherColorMode != null) colormode = mp.OtherColorMode; if (mp != null && mp.RainbowPresserColorMode) - colormode = "rpc"; + colormode = ChatFormatter.Color.RPC; if (message.startsWith(">")) - colormode = "green"; // If greentext, ignore channel or player - // colors + colormode = ChatFormatter.Color.Green; + // If greentext, ignore channel or player colors + + if (!colormode.equals(ChatFormatter.Color.RPC)) + formatters.add(new ChatFormatter(Pattern.compile(".+"), colormode, + "")); String formattedmessage = message; - formattedmessage = formattedmessage.replace("\\", "\\\\"); // It's - // really - // important - // to escape - // the - // slashes - // first + formattedmessage = formattedmessage.replace("\\", "\\\\"); formattedmessage = formattedmessage.replace("\"", "\\\""); - if (PluginMain.permission.has(sender, "tbmc.admin")) - formattedmessage = formattedmessage.replace("&", "§"); - formattedmessage = formattedmessage.replace("§r", "§" - + currentchannel.DisplayName.charAt(1)); + // ^ Tellraw support, needed for both the message and suggestmsg + // TODO: Only apply after the formatters, or escaping won't work + String suggestmsg = formattedmessage; - boolean cont = true; - while (cont) { - int first_under = formattedmessage.indexOf("_"); - if (first_under != -1 - && formattedmessage.indexOf("_", first_under + 1) != -1) // underline - { - formattedmessage = formattedmessage.replaceFirst("_", "§n") - .replaceFirst("_", "§r"); - continue; - } - - int first_bold = formattedmessage.indexOf("**"); - if (first_bold != -1 - && formattedmessage.indexOf("**", first_bold + 1) != -1) // bold - { - formattedmessage = formattedmessage - .replaceFirst("\\*\\*", "§l").replaceFirst("\\*\\*", - "§r"); - continue; - } - int first = formattedmessage.indexOf('*'); - if (first != -1 && formattedmessage.indexOf('*', first + 1) != -1) { - formattedmessage = formattedmessage.replaceFirst("\\*", "§o") - .replaceFirst("\\*", "§r"); - continue; - } - cont = false; - } + formatters + .add(new ChatFormatter( + Pattern.compile("(? 0) player.sendMessage(String.format( "§eMessage color set to %s", p.OtherColorMode));