From 7f7f84a4c48757b3fc0fd79f3fc9201464e05a3c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 21 Jan 2025 00:03:39 +0100 Subject: [PATCH] Fix CouncilChannel, unloading issues --- .../src/de/steamwar/velocitycore/VelocityCore.java | 12 +++++++++++- .../de/steamwar/velocitycore/discord/DiscordBot.java | 2 +- .../discord/channels/CouncilChannel.java | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 5e6dca1d..3cec098b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -252,7 +252,17 @@ public class VelocityCore implements ReloadablePlugin { @Override public void onProxyShutdown(ProxyShutdownEvent event) { try { - DiscordBot.withBot(bot -> bot.getJda().shutdownNow()); + DiscordBot.withBot(bot -> { + bot.getJda().shutdownNow(); + bot.getJda().getHttpClient().connectionPool().evictAll(); + bot.getJda().getHttpClient().dispatcher().executorService().shutdown(); + try { + if(!bot.getJda().awaitShutdown(1, TimeUnit.SECONDS)) + logger.log(Level.SEVERE, "Could not await discord bot shutdown"); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }); } catch (Throwable e) { logger.log(Level.SEVERE, "Could not shutdown discord bot", e); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 89167565..d2f7419a 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -97,7 +97,7 @@ public class DiscordBot { .createDefault(config.getToken()) .setStatus(OnlineStatus.ONLINE) .setMemberCachePolicy(MemberCachePolicy.ONLINE) - .enableIntents(GatewayIntent.MESSAGE_CONTENT) + .enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.MESSAGE_CONTENT) .build(); instance = this; diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java index 6a949d0b..7c86c1b0 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -48,7 +48,7 @@ public class CouncilChannel extends StaticMessageChannel { MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder(); messageCreateBuilder.setContent("# Ratsmitglieder"); - for (Member member : DiscordBot.getGuild().getMembersWithRoles(role)) { + for (Member member : DiscordBot.getGuild().findMembersWithRoles(role).get()) { SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); if (steamwarUser == null) continue;