From ab96df2d4706f18ad85594be5f11f62fae3e9906 Mon Sep 17 00:00:00 2001 From: Bram Date: Thu, 10 Oct 2024 12:55:50 +0200 Subject: [PATCH] ReloadCommand is now being executed asynchronously --- .../commands/TotemGuardCommand.java | 2 +- .../commands/totemguard/ReloadCommand.java | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/deathmotion/totemguard/commands/TotemGuardCommand.java b/src/main/java/com/deathmotion/totemguard/commands/TotemGuardCommand.java index 4cbeee8..e8eaf2e 100644 --- a/src/main/java/com/deathmotion/totemguard/commands/TotemGuardCommand.java +++ b/src/main/java/com/deathmotion/totemguard/commands/TotemGuardCommand.java @@ -46,7 +46,7 @@ public class TotemGuardCommand implements CommandExecutor, TabExecutor { public TotemGuardCommand(TotemGuard plugin) { subCommands.put("info", new InfoCommand(plugin)); subCommands.put("alerts", new AlertsCommand(plugin)); - subCommands.put("reload", new ReloadCommand(plugin.getConfigManager())); + subCommands.put("reload", new ReloadCommand(plugin)); subCommands.put("profile", new ProfileCommand(plugin)); subCommands.put("stats", new StatsCommand(plugin)); subCommands.put("clearlogs", new ClearLogsCommand(plugin)); diff --git a/src/main/java/com/deathmotion/totemguard/commands/totemguard/ReloadCommand.java b/src/main/java/com/deathmotion/totemguard/commands/totemguard/ReloadCommand.java index f1442cd..dd5cb9e 100644 --- a/src/main/java/com/deathmotion/totemguard/commands/totemguard/ReloadCommand.java +++ b/src/main/java/com/deathmotion/totemguard/commands/totemguard/ReloadCommand.java @@ -18,8 +18,10 @@ package com.deathmotion.totemguard.commands.totemguard; +import com.deathmotion.totemguard.TotemGuard; import com.deathmotion.totemguard.commands.SubCommand; import com.deathmotion.totemguard.config.ConfigManager; +import io.github.retrooper.packetevents.util.folia.FoliaScheduler; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -28,22 +30,26 @@ import java.util.List; public class ReloadCommand implements SubCommand { + private final TotemGuard plugin; private final ConfigManager configManager; - public ReloadCommand(ConfigManager configManager) { - this.configManager = configManager; + public ReloadCommand(TotemGuard plugin) { + this.plugin = plugin; + this.configManager = plugin.getConfigManager(); } @Override public boolean execute(CommandSender sender, String[] args) { - configManager.reload(); + FoliaScheduler.getAsyncScheduler().runNow(plugin, (o) -> { + configManager.reload(); - Component message = Component.text() - .append(LegacyComponentSerializer.legacyAmpersand().deserialize(configManager.getSettings().getPrefix())) - .append(Component.text("The configuration has been reloaded!", NamedTextColor.GREEN)) - .build(); + Component message = Component.text() + .append(LegacyComponentSerializer.legacyAmpersand().deserialize(configManager.getSettings().getPrefix())) + .append(Component.text("The configuration has been reloaded!", NamedTextColor.GREEN)) + .build(); - sender.sendMessage(message); + sender.sendMessage(message); + }); return true; }