From 6e931b2b3b620dc7fc98222ff18a7e76979bb43f Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Fri, 11 Nov 2022 18:28:55 -0500 Subject: [PATCH] Fix ConsoleInjector not getting reinjecting on reload (#5149) --- .../java/net/essentialsx/discord/JDADiscordService.java | 2 +- .../java/net/essentialsx/discord/util/ConsoleInjector.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java index a9057d9f6..129b64985 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java @@ -392,7 +392,7 @@ public class JDADiscordService implements DiscordService, IEssentialsModule { shutdownConsoleRelay(false); consoleWebhook = DiscordUtil.getWebhookClient(webhookId, webhookToken, jda.getHttpClient()); - if (injector == null) { + if (injector == null || injector.isRemoved()) { injector = new ConsoleInjector(this); injector.start(); } diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java index 977efb37b..3d2502770 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java @@ -27,6 +27,7 @@ public class ConsoleInjector extends AbstractAppender { private final JDADiscordService jda; private final BlockingQueue messageQueue = new LinkedBlockingQueue<>(); private final int taskId; + private boolean removed = false; public ConsoleInjector(JDADiscordService jda) { super("EssentialsX-ConsoleInjector", null, null, false); @@ -93,5 +94,10 @@ public class ConsoleInjector extends AbstractAppender { ((Logger) LogManager.getRootLogger()).removeAppender(this); Bukkit.getScheduler().cancelTask(taskId); messageQueue.clear(); + removed = true; + } + + public boolean isRemoved() { + return removed; } }