diff --git a/api/src/main/java/com/alttd/chat/objects/chat_log/ChatLogHandler.java b/api/src/main/java/com/alttd/chat/objects/chat_log/ChatLogHandler.java index 93fd6f5..9eafa84 100644 --- a/api/src/main/java/com/alttd/chat/objects/chat_log/ChatLogHandler.java +++ b/api/src/main/java/com/alttd/chat/objects/chat_log/ChatLogHandler.java @@ -15,11 +15,11 @@ import java.util.concurrent.*; public class ChatLogHandler { private static ChatLogHandler instance = null; - private final ScheduledExecutorService executorService; + private ScheduledExecutorService executorService = null; - public static ChatLogHandler getInstance() { + public static ChatLogHandler getInstance(boolean enableLogging) { if (instance == null) - instance = new ChatLogHandler(); + instance = new ChatLogHandler(enableLogging); return instance; } @@ -27,7 +27,9 @@ public class ChatLogHandler { private final Queue chatLogQueue = new ConcurrentLinkedQueue<>(); private final HashMap> chatLogs = new HashMap<>(); - public ChatLogHandler() { + public ChatLogHandler(boolean enableLogging) { + if (!enableLogging) + return; Duration deleteThreshold = Duration.ofDays(Config.CHAT_LOG_DELETE_OLDER_THAN_DAYS); ChatLogQueries.deleteOldMessages(deleteThreshold).thenAccept(success -> { if (success) { @@ -41,6 +43,10 @@ public class ChatLogHandler { Config.CHAT_LOG_SAVE_DELAY_MINUTES, Config.CHAT_LOG_SAVE_DELAY_MINUTES, TimeUnit.MINUTES); } + /** + * Shuts down the executor service and saves the chat logs to the database. + * Will throw an error if called on a ChatLogHandler that was started without logging + */ public void shutDown() { executorService.shutdown(); saveToDatabase(true); diff --git a/galaxy/src/main/java/com/alttd/chat/ChatPlugin.java b/galaxy/src/main/java/com/alttd/chat/ChatPlugin.java index 6056d46..d56d317 100755 --- a/galaxy/src/main/java/com/alttd/chat/ChatPlugin.java +++ b/galaxy/src/main/java/com/alttd/chat/ChatPlugin.java @@ -39,7 +39,7 @@ public class ChatPlugin extends JavaPlugin { chatHandler = new ChatHandler(); DatabaseConnection.initialize(); serverConfig = new ServerConfig(Bukkit.getServerName()); - ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(); + ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true); registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler)); if(serverConfig.GLOBALCHAT) { registerCommand("globalchat", new GlobalChat()); diff --git a/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java b/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java index a53c34e..d7cb3a9 100755 --- a/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java +++ b/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java @@ -110,7 +110,7 @@ public class VelocityChat { } public void loadCommands() { - ChatLogHandler instance = ChatLogHandler.getInstance(); //TODO disable logging part + ChatLogHandler instance = ChatLogHandler.getInstance(false); new SilentJoinCommand(server); new GlobalAdminChat(server); new Reload(server);