From a87c71f37b09a259b3127a26f83574738feecc23 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 15 Nov 2016 22:34:07 +0100 Subject: [PATCH] Moved everything for Channel.java --- src/main/java/buttondevteam/chat/Channel.java | 38 ------------- .../java/buttondevteam/chat/ChatPlayer.java | 3 +- .../buttondevteam/chat/ChatProcessing.java | 36 ++++++------ .../chat/commands/ucmds/CCommand.java | 4 +- .../chat/formatting/ChatFormatter.java | 57 +------------------ .../chat/formatting/ChatFormatterBuilder.java | 4 +- .../chat/formatting/TellrawEvent.java | 2 + .../chat/formatting/TellrawPart.java | 18 +++--- .../formatting/TellrawSerializableEnum.java | 5 -- .../chat/formatting/TellrawSerializer.java | 2 + .../chat/listener/PlayerListener.java | 2 +- 11 files changed, 40 insertions(+), 131 deletions(-) delete mode 100644 src/main/java/buttondevteam/chat/Channel.java delete mode 100644 src/main/java/buttondevteam/chat/formatting/TellrawSerializableEnum.java diff --git a/src/main/java/buttondevteam/chat/Channel.java b/src/main/java/buttondevteam/chat/Channel.java deleted file mode 100644 index 941c15c..0000000 --- a/src/main/java/buttondevteam/chat/Channel.java +++ /dev/null @@ -1,38 +0,0 @@ -package buttondevteam.chat; - -import java.util.ArrayList; -import java.util.List; - -import buttondevteam.chat.formatting.ChatFormatter; - -public class Channel { - public final String DisplayName; - public final ChatFormatter.Color Color; - public final String Command; - - private static List channels = new ArrayList<>(); - - public Channel(String displayname, ChatFormatter.Color color, String command) { - DisplayName = displayname; - Color = color; - Command = command; - } - - static { - channels.add(GlobalChat = new Channel("§fg§f", ChatFormatter.Color.White, "g")); - channels.add(TownChat = new Channel("§3TC§f", ChatFormatter.Color.DarkAqua, "tc")); - channels.add(NationChat = new Channel("§6NC§f", ChatFormatter.Color.Gold, "nc")); - channels.add(AdminChat = new Channel("§cADMIN§f", ChatFormatter.Color.Red, "a")); - channels.add(ModChat = new Channel("§9MOD§f", ChatFormatter.Color.Blue, "mod")); - } - - public static List getChannels() { - return channels; - } - - public static Channel GlobalChat; - public static Channel TownChat; - public static Channel NationChat; - public static Channel AdminChat; - public static Channel ModChat; -} diff --git a/src/main/java/buttondevteam/chat/ChatPlayer.java b/src/main/java/buttondevteam/chat/ChatPlayer.java index 806c1d1..ddcf935 100644 --- a/src/main/java/buttondevteam/chat/ChatPlayer.java +++ b/src/main/java/buttondevteam/chat/ChatPlayer.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import buttondevteam.chat.formatting.ChatFormatter; import buttondevteam.lib.TBMCPlayer; +import buttondevteam.lib.chat.*; public class ChatPlayer extends TBMCPlayer { public String getUserName() { @@ -73,7 +74,7 @@ public class ChatPlayer extends TBMCPlayer { public Channel CurrentChannel = Channel.GlobalChat; public boolean SendingLink = false; public boolean RainbowPresserColorMode = false; - public ChatFormatter.Color OtherColorMode = null; + public Color OtherColorMode = null; public boolean ChatOnly = false; public int LoginWarningCount = 0; diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index b20a6b1..2555fc1 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -24,12 +24,12 @@ import buttondevteam.chat.formatting.ChatFormatter; import buttondevteam.chat.formatting.ChatFormatterBuilder; import buttondevteam.chat.formatting.TellrawEvent; import buttondevteam.chat.formatting.TellrawPart; -import buttondevteam.chat.formatting.TellrawSerializableEnum; import buttondevteam.chat.formatting.TellrawSerializer; import buttondevteam.lib.TBMCPlayer; -import buttondevteam.chat.formatting.ChatFormatter.Color; -import buttondevteam.chat.formatting.ChatFormatter.Priority; +import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.TellrawSerializableEnum; import buttondevteam.chat.listener.PlayerListener; +import buttondevteam.lib.chat.*; public class ChatProcessing { private static final Pattern ESCAPE_PATTERN = Pattern.compile("\\\\([\\*\\_\\\\])"); @@ -85,13 +85,13 @@ public class ChatProcessing { ArrayList formatters = new ArrayList(); - ChatFormatter.Color colormode = currentchannel.Color; + Color colormode = currentchannel.color; if (mp != null && mp.OtherColorMode != null) colormode = mp.OtherColorMode; if (mp != null && mp.RainbowPresserColorMode) - colormode = ChatFormatter.Color.RPC; + colormode = Color.RPC; if (message.startsWith(">")) - colormode = ChatFormatter.Color.Green; + colormode = Color.Green; // If greentext, ignore channel or player colors formatters.add(new ChatFormatterBuilder().setRegex(ENTIRE_MESSAGE_PATTERN).setColor(colormode) @@ -101,17 +101,17 @@ public class ChatProcessing { String suggestmsg = formattedmessage; - formatters.add(new ChatFormatterBuilder().setRegex(BOLD_PATTERN).setFormat(ChatFormatter.Format.Bold) + formatters.add(new ChatFormatterBuilder().setRegex(BOLD_PATTERN).setFormat(Format.Bold) .setRemoveCharCount((short) 2).build()); - formatters.add(new ChatFormatterBuilder().setRegex(ITALIC_PATTERN).setFormat(ChatFormatter.Format.Italic) + formatters.add(new ChatFormatterBuilder().setRegex(ITALIC_PATTERN).setFormat(Format.Italic) + .setRemoveCharCount((short) 1).build()); + formatters.add(new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN).setFormat(Format.Underlined) .setRemoveCharCount((short) 1).build()); - formatters.add(new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN) - .setFormat(ChatFormatter.Format.Underlined).setRemoveCharCount((short) 1).build()); formatters.add(new ChatFormatterBuilder().setRegex(ESCAPE_PATTERN).setRemoveCharPos((short) 0).build()); // URLs + Rainbow text - formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(ChatFormatter.Format.Underlined) - .setOpenlink("$1").build()); + formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(Format.Underlined).setOpenlink("$1") + .build()); if (PluginMain.GetPlayers().size() > 0) { StringBuilder namesb = new StringBuilder(); namesb.append("(?i)("); @@ -126,8 +126,8 @@ public class ChatProcessing { nicksb.deleteCharAt(nicksb.length() - 1); nicksb.append(")"); - formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(namesb.toString())) - .setColor(ChatFormatter.Color.Aqua).setOnmatch((String match) -> { + formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(namesb.toString())).setColor(Color.Aqua) + .setOnmatch((String match) -> { Player p = Bukkit.getPlayer(match); if (p == null) { PluginMain.Instance.getLogger() @@ -144,8 +144,8 @@ public class ChatProcessing { return color + p.getName() + "§r"; }).setPriority(Priority.High).build()); - formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString())) - .setColor(ChatFormatter.Color.Aqua).setOnmatch((String match) -> { + formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString())).setColor(Color.Aqua) + .setOnmatch((String match) -> { if (PlayerListener.nicknames.containsKey(match)) { Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match)); if (p == null) { @@ -167,7 +167,7 @@ public class ChatProcessing { } pingedconsole = false; - formatters.add(new ChatFormatterBuilder().setRegex(CONSOLE_PING_PATTERN).setColor(ChatFormatter.Color.Aqua) + formatters.add(new ChatFormatterBuilder().setRegex(CONSOLE_PING_PATTERN).setColor(Color.Aqua) .setOnmatch((String match) -> { if (!pingedconsole) { System.out.print("\007"); @@ -176,7 +176,7 @@ public class ChatProcessing { return match; }).setPriority(Priority.High).build()); - formatters.add(new ChatFormatterBuilder().setRegex(HASHTAG_PATTERN).setColor(ChatFormatter.Color.Blue) + formatters.add(new ChatFormatterBuilder().setRegex(HASHTAG_PATTERN).setColor(Color.Blue) .setOpenlink("https://twitter.com/hashtag/$1").setPriority(Priority.High).build()); /* diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java index 5001d92..f0eeef7 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java @@ -5,8 +5,8 @@ import org.bukkit.entity.Player; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PluginMain; -import buttondevteam.chat.formatting.ChatFormatter; import buttondevteam.lib.TBMCPlayer; +import buttondevteam.lib.chat.*; public class CCommand extends UCommandBase { @@ -37,7 +37,7 @@ public class CCommand extends UCommandBase { p.RainbowPresserColorMode = false; p.OtherColorMode = null; try { - p.OtherColorMode = ChatFormatter.Color.valueOf(args[0].toLowerCase()); + p.OtherColorMode = Color.valueOf(args[0].toLowerCase()); } catch (Exception e) { player.sendMessage("§cUnknown message color: " + args[0]); player.sendMessage("§cUse color names, like blue, or dark_aqua"); diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java index 317bd94..0594c93 100644 --- a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java +++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java @@ -8,6 +8,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import buttondevteam.chat.commands.ucmds.admin.DebugCommand; +import buttondevteam.lib.chat.*; public final class ChatFormatter { private Pattern regex; @@ -168,7 +169,7 @@ public final class ChatFormatter { if (formatter.color != null) color = formatter.color; if (formatter.format != null) - format = formatter.format.flag; //TODO: Fix + format = formatter.format.getFlag(); //TODO: Fix if (formatter.openlink != null) openlink = formatter.openlink; } @@ -193,58 +194,4 @@ public final class ChatFormatter { return new StringBuilder("F(").append(color).append(", ").append(format).append(", ").append(openlink) .append(", ").append(priority).append(")").toString(); } - - public enum Format implements TellrawSerializableEnum { - Bold("bold"), Underlined("underlined"), Italic("italic"), Strikethrough("strikethrough"), Obfuscated( - "obfuscated"); - // TODO: Add format codes to /u c - private String name; - - Format(String name) { - this.name = name; - this.flag = 1 << this.ordinal(); - } - - @Override - public String getName() { - return name; - } - - private final int flag; - - public int getFlag() { - return flag; - } - } - - public enum Color implements TellrawSerializableEnum { - Black("black"), DarkBlue("dark_blue"), DarkGreen("dark_green"), DarkAqua("dark_aqua"), DarkRed( - "dark_red"), DarkPurple("dark_purple"), Gold("gold"), Gray("gray"), DarkGray("dark_gray"), Blue( - "blue"), Green("green"), Aqua("aqua"), Red( - "red"), LightPurple("light_purple"), Yellow("yellow"), White("white"), RPC("rpc"); - - private String name; - - Color(String name) { - this.name = name; - } - - @Override - public String getName() { - return name; - } - } - - public enum Priority { - Low(0), Normal(1), High(2); - private int val; - - Priority(int v) { - val = v; - } - - public int GetValue() { - return val; - } - } } diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java index 5558f04..2277b10 100644 --- a/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java +++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java @@ -3,9 +3,7 @@ package buttondevteam.chat.formatting; import java.util.function.Function; import java.util.regex.Pattern; -import buttondevteam.chat.formatting.ChatFormatter.Color; -import buttondevteam.chat.formatting.ChatFormatter.Format; -import buttondevteam.chat.formatting.ChatFormatter.Priority; +import buttondevteam.lib.chat.*; public class ChatFormatterBuilder { private Pattern regex; diff --git a/src/main/java/buttondevteam/chat/formatting/TellrawEvent.java b/src/main/java/buttondevteam/chat/formatting/TellrawEvent.java index b989d45..4e18dc0 100644 --- a/src/main/java/buttondevteam/chat/formatting/TellrawEvent.java +++ b/src/main/java/buttondevteam/chat/formatting/TellrawEvent.java @@ -2,6 +2,8 @@ package buttondevteam.chat.formatting; import java.io.Serializable; +import buttondevteam.lib.chat.TellrawSerializableEnum; + public final class TellrawEvent implements Serializable { private static final long serialVersionUID = -1681364161210561505L; private transient boolean hoverEvent; diff --git a/src/main/java/buttondevteam/chat/formatting/TellrawPart.java b/src/main/java/buttondevteam/chat/formatting/TellrawPart.java index c9145dc..4caacb1 100644 --- a/src/main/java/buttondevteam/chat/formatting/TellrawPart.java +++ b/src/main/java/buttondevteam/chat/formatting/TellrawPart.java @@ -4,10 +4,12 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import buttondevteam.lib.chat.*; + @SuppressWarnings("unused") public final class TellrawPart implements Serializable { private static final long serialVersionUID = 4125357644462144024L; - private ChatFormatter.Color color; + private Color color; private transient int format; private boolean italic; private boolean bold; @@ -23,11 +25,11 @@ public final class TellrawPart implements Serializable { this.text = text; } - public ChatFormatter.Color getColor() { + public Color getColor() { return color; } - public TellrawPart setColor(ChatFormatter.Color color) { + public TellrawPart setColor(Color color) { this.color = color; return this; } @@ -43,15 +45,15 @@ public final class TellrawPart implements Serializable { this.underlined = false; this.strikethrough = false; this.obfuscated = false; - if ((format & ChatFormatter.Format.Italic.getFlag()) != 0) + if ((format & Format.Italic.getFlag()) != 0) this.italic = true; - else if ((format & ChatFormatter.Format.Bold.getFlag()) != 0) + else if ((format & Format.Bold.getFlag()) != 0) this.bold = true; - else if ((format & ChatFormatter.Format.Underlined.getFlag()) != 0) + else if ((format & Format.Underlined.getFlag()) != 0) this.underlined = true; - else if ((format & ChatFormatter.Format.Strikethrough.getFlag()) != 0) + else if ((format & Format.Strikethrough.getFlag()) != 0) this.strikethrough = true; - else if ((format & ChatFormatter.Format.Obfuscated.getFlag()) != 0) + else if ((format & Format.Obfuscated.getFlag()) != 0) this.obfuscated = true; else throw new UnsupportedOperationException("Trying to set to an unknown format!"); diff --git a/src/main/java/buttondevteam/chat/formatting/TellrawSerializableEnum.java b/src/main/java/buttondevteam/chat/formatting/TellrawSerializableEnum.java deleted file mode 100644 index 9fc8ac2..0000000 --- a/src/main/java/buttondevteam/chat/formatting/TellrawSerializableEnum.java +++ /dev/null @@ -1,5 +0,0 @@ -package buttondevteam.chat.formatting; - -public interface TellrawSerializableEnum { - public String getName(); -} diff --git a/src/main/java/buttondevteam/chat/formatting/TellrawSerializer.java b/src/main/java/buttondevteam/chat/formatting/TellrawSerializer.java index 2eee0cf..f8b591e 100644 --- a/src/main/java/buttondevteam/chat/formatting/TellrawSerializer.java +++ b/src/main/java/buttondevteam/chat/formatting/TellrawSerializer.java @@ -7,6 +7,8 @@ import java.util.Collection; import com.google.gson.*; import com.google.gson.stream.*; +import buttondevteam.lib.chat.TellrawSerializableEnum; + public abstract class TellrawSerializer { public static class TwEnum extends TypeAdapter { @Override diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index ee323b2..c06f1c5 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -32,13 +32,13 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import au.com.mineauz.minigames.MinigamePlayer; import au.com.mineauz.minigames.Minigames; -import buttondevteam.chat.Channel; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.ChatProcessing; import buttondevteam.chat.PluginMain; import buttondevteam.chat.commands.ucmds.KittycannonCommand; import buttondevteam.lib.TBMCPlayer; import buttondevteam.lib.TBMCPlayer.InfoTarget; +import buttondevteam.lib.chat.Channel; import buttondevteam.lib.TBMCPlayerGetInfoEvent; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap;