From 428c63429c9a69b5f2acee21d7470141a2c9ebce Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 10 Jun 2025 17:26:20 +0200 Subject: [PATCH] Add 'queuerestart' command --- .../de/steamwar/persistent/Persistent.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java index bc5fd1ed..31159955 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Persistent.java @@ -24,9 +24,11 @@ import com.google.inject.Inject; import com.google.inject.Module; import com.google.inject.name.Names; import com.mojang.brigadier.Command; +import com.mojang.brigadier.context.CommandContext; import com.velocitypowered.api.command.BrigadierCommand; import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.command.CommandMeta; +import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; @@ -71,12 +73,20 @@ public class Persistent { private final Logger logger; private final Path directory; + private boolean restartQueued = false; + @Inject public Persistent(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory) { instance = this; this.proxy = proxy; this.logger = logger; this.directory = dataDirectory; + + proxy.getScheduler().buildTask(instance, () -> { + if (!restartQueued) return; + if (!proxy.getAllPlayers().isEmpty()) return; + proxy.shutdown(); + }).repeat(10, TimeUnit.SECONDS).schedule(); } @Subscribe @@ -89,6 +99,14 @@ public class Persistent { .build() ) ); + proxy.getCommandManager().register( + new BrigadierCommand( + BrigadierCommand.literalArgumentBuilder("queuerestart") + .requires(commandSource -> commandSource.hasPermission("bungeecore.softreload")) + .executes(this::queueRestart) + .build() + ) + ); } @Subscribe @@ -97,6 +115,7 @@ public class Persistent { } public int softreload() { + restartQueued = false; PluginContainer container = null; ReloadablePlugin plugin = null; try { @@ -200,4 +219,10 @@ public class Persistent { ResourceBundle.clearCache(classLoader); classLoader.close(); } + + public int queueRestart(CommandContext context) { + restartQueued = true; + context.getSource().sendRichMessage("§eRestart queued§8."); + return Command.SINGLE_SUCCESS; + } }