From 10cb0e81f14c326c4c5718fdd814dfa45d3790a0 Mon Sep 17 00:00:00 2001 From: Ilya Andreev Date: Sat, 6 Jul 2024 13:17:12 +0300 Subject: [PATCH] Fix stacktraces on server shutdown when using native adventure platform --- .../main/java/ru/brikster/chatty/Chatty.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/spigot/src/main/java/ru/brikster/chatty/Chatty.java b/spigot/src/main/java/ru/brikster/chatty/Chatty.java index 3be99ee..f1bff29 100644 --- a/spigot/src/main/java/ru/brikster/chatty/Chatty.java +++ b/spigot/src/main/java/ru/brikster/chatty/Chatty.java @@ -29,8 +29,6 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import ru.brikster.chatty.adventure.NativeBukkitAudienceProvider; import ru.brikster.chatty.api.ChattyApiImpl; import ru.brikster.chatty.api.event.ChattyInitEvent; @@ -70,7 +68,6 @@ public final class Chatty extends JavaPlugin { - private static final Logger log = LoggerFactory.getLogger(Chatty.class); private final Map> proxyingCommandHandlerMap = new ConcurrentHashMap<>(); private Injector injector; @@ -140,7 +137,7 @@ private void registerChattyCommand() throws Exception { private void initialize() throws Exception { BukkitAudiences audiences; - if (PaperUtil.isPaper() && PaperUtil.isSupportAdventure()) { + if (isUseNativeAdventurePlatform()) { getLogger().log(Level.INFO, "Using native Adventure audience provider"); audiences = new NativeBukkitAudienceProvider(); } else { @@ -207,7 +204,9 @@ private void initialize() throws Exception { if (this.asyncCommandManager == null) { initAsyncCommandManager(); - if (pmConfig.isEnable()) registerPmCommands(commandSuggestionsProvider); + if (pmConfig.isEnable()) { + registerPmCommands(commandSuggestionsProvider); + } registerIgnoreCommand(commandSuggestionsProvider); registerClearChatCommand(); } @@ -216,7 +215,9 @@ private void initialize() throws Exception { } private void closeResources() throws IOException { - BukkitAudiences.create(this).close(); + if (!isUseNativeAdventurePlatform()) { + BukkitAudiences.create(this).close(); + } injector.getInstance(PlayerDataRepository.class).close(); injector.getInstance(ProxyService.class).close(); ListenerUtil.unregister(PlayerJoinEvent.class, this); @@ -353,4 +354,8 @@ private static void unregisterAllCommands(BukkitCommandManager co } } + private static boolean isUseNativeAdventurePlatform() { + return PaperUtil.isPaper() && PaperUtil.isSupportAdventure(); + } + }