Skip to content

Commit

Permalink
Fix stacktraces on server shutdown when using native adventure platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Brikster committed Jul 6, 2024
1 parent 01d0a5e commit 10cb0e8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions spigot/src/main/java/ru/brikster/chatty/Chatty.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,7 +68,6 @@

public final class Chatty extends JavaPlugin {

private static final Logger log = LoggerFactory.getLogger(Chatty.class);
private final Map<String, ProxyingCommandHandler<CommandSender>> proxyingCommandHandlerMap = new ConcurrentHashMap<>();

private Injector injector;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
Expand Down Expand Up @@ -353,4 +354,8 @@ private static void unregisterAllCommands(BukkitCommandManager<CommandSender> co
}
}

private static boolean isUseNativeAdventurePlatform() {
return PaperUtil.isPaper() && PaperUtil.isSupportAdventure();
}

}

0 comments on commit 10cb0e8

Please sign in to comment.