From 06a1ce9ef2c1dec280001ea5bb1a6f0bb14f2ed0 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 14 Oct 2023 19:04:23 +0700 Subject: [PATCH] some console fixes (more ohio) + wait until executorservice shut down --- .../land/chipmunk/chayapak/chomens_bot/Main.java | 11 +++++++++++ .../chayapak/chomens_bot/plugins/ConsolePlugin.java | 12 +----------- .../chomens_bot/plugins/FormatCheckerPlugin.java | 5 ++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java index 9b23541..82abaef 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java @@ -125,6 +125,17 @@ public class Main { System.exit(1); } }, 0, 1, TimeUnit.MINUTES); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + final boolean success = executorService.awaitTermination(3, TimeUnit.SECONDS); + + if (!success) System.exit(1); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + })); } public static void initializeBots() { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java index e43cbaa..bbe7a53 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java @@ -1,6 +1,5 @@ package land.chipmunk.chayapak.chomens_bot.plugins; -import com.github.steveice10.packetlib.event.session.ConnectedEvent; import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.Configuration; import land.chipmunk.chayapak.chomens_bot.Main; @@ -24,8 +23,6 @@ public class ConsolePlugin implements Completer { public String prefix; - public Component formatPrefix; - private static final List listeners = new ArrayList<>(); public ConsolePlugin (List allBots, Configuration discordConfig, JDA jda) { @@ -42,13 +39,6 @@ public class ConsolePlugin implements Completer { bot.console = this; - bot.addListener(new Bot.Listener() { - @Override - public void connected(ConnectedEvent event) { - bot.console.formatPrefix = Component.text(bot.username + " Console").color(NamedTextColor.GRAY); - } - }); - bot.logger = new LoggerPlugin(bot); } @@ -114,7 +104,7 @@ public class ConsolePlugin implements Completer { bot.chat.tellraw( Component.translatable( "[%s] %s › %s", - formatPrefix, + Component.text(bot.username + " Console").color(NamedTextColor.GRAY), Component.text(bot.config.ownerName).color(ColorUtilities.getColorByString(bot.config.colorPalette.ownerName)), Component.text(line).color(NamedTextColor.GRAY) ).color(NamedTextColor.DARK_GRAY) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/FormatCheckerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/FormatCheckerPlugin.java index a157438..082cff3 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/FormatCheckerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/FormatCheckerPlugin.java @@ -67,7 +67,10 @@ public class FormatCheckerPlugin extends ChatPlugin.Listener { final Component prefix = format.args().get(0); - if (prefix.equals(bot.console.formatPrefix) || (bot.discord != null && prefix.equals(bot.discord.messagePrefix))) return false; + if ( + ((prefix instanceof TextComponent text) && text.content().equals(bot.username + " Console")) || // ohio + (bot.discord != null && prefix.equals(bot.discord.messagePrefix)) + ) return false; if (!(prefix instanceof TranslatableComponent translatablePrefix)) return true;