Skip to content

Commit

Permalink
ReloadCommand is now being executed asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram1903 committed Oct 10, 2024
1 parent 1117787 commit ab96df2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit ab96df2

Please sign in to comment.