From bfe7d48760fbe623106608b933e2feb3ea51d1c2 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 9 Jan 2019 18:57:21 +0100 Subject: [PATCH] Towny logger works TBMCPlugins/DiscordPlugin#81 --- src/main/java/buttondevteam/chat/ChatProcessing.java | 2 +- src/main/java/buttondevteam/chat/PluginMain.java | 6 ++++++ .../chat/components/TownyAnnouncer.java | 12 ++++++++---- .../chat/components/TownyComponent.java | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 5867e8c..e0cafa4 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -87,7 +87,7 @@ public class ChatProcessing { .registerTypeAdapter(Boolean.class, new TellrawSerializer.TwBool()) .registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create(); private static final String[] testPlayers = {"Koiiev", "iie", "Alisolarflare", "NorbiPeti", "Arsen_Derby_FTW", "carrot_lynx"}; - static final String MCORIGIN = "Minecraft"; //Shouldn't change, like ever - TBMCPlayer.getFolderForType(TBMCPlayer.class) capitalized + public static final String MCORIGIN = "Minecraft"; //Shouldn't change, like ever - TBMCPlayer.getFolderForType(TBMCPlayer.class) capitalized private ChatProcessing() { } diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index de05ca8..8c96781 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -2,10 +2,13 @@ package buttondevteam.chat; import buttondevteam.chat.commands.YeehawCommand; import buttondevteam.chat.commands.ucmds.TownColorCommand; +import buttondevteam.chat.components.TownColorComponent; +import buttondevteam.chat.components.TownyComponent; import buttondevteam.chat.listener.PlayerJoinLeaveListener; import buttondevteam.chat.listener.PlayerListener; import buttondevteam.chat.listener.TownyListener; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.Channel.RecipientTestResult; import buttondevteam.lib.chat.Color; @@ -115,6 +118,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. new Thread(this::FlairGetterThreadMethod).start(); new Thread(new AnnouncerThread()).start(); + + Component.registerComponent(this, new TownyComponent()); + Component.registerComponent(this, new TownColorComponent()); } /** diff --git a/src/main/java/buttondevteam/chat/components/TownyAnnouncer.java b/src/main/java/buttondevteam/chat/components/TownyAnnouncer.java index 3ad6c2a..fb777d7 100644 --- a/src/main/java/buttondevteam/chat/components/TownyAnnouncer.java +++ b/src/main/java/buttondevteam/chat/components/TownyAnnouncer.java @@ -1,5 +1,6 @@ package buttondevteam.chat.components; +import buttondevteam.chat.ChatProcessing; import buttondevteam.chat.PluginMain; import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.TBMCChatAPI; @@ -11,7 +12,7 @@ import java.util.logging.LogRecord; import java.util.regex.Pattern; public class TownyAnnouncer { - private static final Pattern LOG_TYPE_PATTERN = Pattern.compile("\\[(\\w+ (?:Msg|Message))] (\\w+):"); + private static final Pattern LOG_TYPE_PATTERN = Pattern.compile("\\[(\\w+) (?:Msg|Message)](?: (\\w+):)?"); private static final Handler HANDLER = new Handler() { @Override public void publish(LogRecord logRecord) { @@ -23,14 +24,17 @@ public class TownyAnnouncer { case "Town": TBMCChatAPI.SendSystemMessage(PluginMain.TownChat, new Channel.RecipientTestResult(PluginMain.getTownNationIndex(groupID, false), groupID), - logRecord.getMessage()); //TODO: This will also send it in Minecraft + logRecord.getMessage(), ChatProcessing.MCORIGIN); break; case "Nation": TBMCChatAPI.SendSystemMessage(PluginMain.NationChat, new Channel.RecipientTestResult(PluginMain.getTownNationIndex(groupID, true), groupID), - logRecord.getMessage()); //TODO: This will also send it in Minecraft + logRecord.getMessage(), ChatProcessing.MCORIGIN); break; - case "Global": //TODO + case "Global": + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, + Channel.RecipientTestResult.ALL, + logRecord.getMessage(), ChatProcessing.MCORIGIN); break; } } diff --git a/src/main/java/buttondevteam/chat/components/TownyComponent.java b/src/main/java/buttondevteam/chat/components/TownyComponent.java index 3f1f83e..b176710 100644 --- a/src/main/java/buttondevteam/chat/components/TownyComponent.java +++ b/src/main/java/buttondevteam/chat/components/TownyComponent.java @@ -2,7 +2,7 @@ package buttondevteam.chat.components; import buttondevteam.lib.architecture.Component; -public class TownyComponent extends Component { //TODO: Register component +public class TownyComponent extends Component { @Override protected void enable() { TownyAnnouncer.setup();