From 0b3dae61f667f5f1aafbcea3691fe4f939907391 Mon Sep 17 00:00:00 2001 From: Strafbefehl Date: Sun, 12 Nov 2023 09:16:23 +0100 Subject: [PATCH] ShardManager replaced by DefaultShardManager --- .idea/misc.xml | 1 - .../java/rystudio/strafbefehl/vinyl/Core.java | 29 +++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 463551f..926d070 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/src/main/java/rystudio/strafbefehl/vinyl/Core.java b/src/main/java/rystudio/strafbefehl/vinyl/Core.java index 190e5d0..d208e1a 100644 --- a/src/main/java/rystudio/strafbefehl/vinyl/Core.java +++ b/src/main/java/rystudio/strafbefehl/vinyl/Core.java @@ -15,6 +15,7 @@ import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import net.dv8tion.jda.api.requests.GatewayIntent; +import net.dv8tion.jda.api.sharding.DefaultShardManager; import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder; import net.dv8tion.jda.api.sharding.ShardManager; import net.dv8tion.jda.api.utils.cache.CacheFlag; @@ -44,9 +45,8 @@ public class Core extends ListenerAdapter { public JDA jda; private boolean running; - private ShardManager shardManager; - private DefaultShardManagerBuilder builder; + private DefaultShardManager defaultShardManager; // Ändern Sie dies zu DefaultShardManager private MySQL mySQL; @@ -78,7 +78,7 @@ public class Core extends ListenerAdapter { public Core(DefaultShardManagerBuilder builder) throws IOException { config = new Config(); this.logger = new Logger(this); - this.builder = builder; + this.builder = builder; // Diese Zeile kann entfernt werden, da builder bereits als Parameter übergeben wird loadIntents(); this.slashCommands = new SlashCommands(this); @@ -88,7 +88,6 @@ public Core(DefaultShardManagerBuilder builder) throws IOException { getGatewayIntents().add(GatewayIntent.MESSAGE_CONTENT); } - builder = DefaultShardManagerBuilder.create(this.config.getToken(), gatewayIntents); builder.addEventListeners(slashCommands); } @@ -110,7 +109,7 @@ public Core(String token, boolean usePrefixCommands, DefaultShardManagerBuilder } public List buildJDAs(int shardCount) throws InterruptedException { - if (running && shardManager != null) { + if (running && defaultShardManager != null) { stopBot(); } @@ -126,8 +125,8 @@ public List buildJDAs(int shardCount) throws InterruptedException { builder.setShardsTotal(shardCount); builder.setShards(i, shardCount - 1); - ShardManager shardManager = builder.build(); // Build the ShardManager instance - jdaList.add(shardManager.getShardById(i)); // Add the JDA instance to the list + defaultShardManager = (DefaultShardManager) builder.build(); // Cast zu DefaultShardManager + jdaList.add(defaultShardManager.getShardById(i)); // Add the JDA instance to the list jdaList.get(i).awaitReady().getPresence().setActivity(Activity.listening("Shard: " + String.valueOf(i))); jdaList.get(i).addEventListener(this); @@ -162,12 +161,12 @@ public List buildJDAs(int shardCount) throws InterruptedException { public void stopBot() { - if (!running || shardManager == null) { + if (!running || defaultShardManager == null) { return; } - shardManager.shutdown(); + defaultShardManager.shutdown(); running = false; - shardManager = null; + defaultShardManager = null; } @@ -257,8 +256,8 @@ public void onGuildLeave(GuildLeaveEvent event) { } - public ShardManager getShardManager() { - return shardManager; + public DefaultShardManager getDefaultShardManager() { + return defaultShardManager; } private void loadIntents() { @@ -431,8 +430,8 @@ public Core registerListeners(ListenerAdapter... listeners) { if (List.of(listeners).isEmpty()) { return this; } else { - if (this.shardManager == null) { - this.shardManager = DefaultShardManagerBuilder.createDefault(this.config.getToken()).build(); + if (this.defaultShardManager == null) { + this.defaultShardManager = (DefaultShardManager) DefaultShardManagerBuilder.createDefault(this.config.getToken()).build(); // Configure any other settings for the shardManager if needed } @@ -441,7 +440,7 @@ public Core registerListeners(ListenerAdapter... listeners) { for (int var4 = 0; var4 < var3; ++var4) { ListenerAdapter listener = var2[var4]; - this.shardManager.addEventListener(listener); + this.defaultShardManager.addEventListener(listener); Logger.log(LogType.LISTENERS, "Registered listener: " + listener.getClass().getSimpleName()); }