This commit is contained in:
@@ -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<CommandSource> context) {
|
||||
restartQueued = true;
|
||||
context.getSource().sendRichMessage("§eRestart queued§8.");
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user