SchedulerManager console output + Added a simple ShutdownCommand

This commit is contained in:
R0bbyYT 2020-07-29 05:03:07 +02:00
parent 4ad4054fce
commit 56010e27e6
3 changed files with 40 additions and 3 deletions

View File

@ -36,6 +36,7 @@ public class Main {
commandManager.register(new SimpleCommand());
commandManager.register(new GamemodeCommand());
commandManager.register(new DimensionCommand());
commandManager.register(new ShutdownCommand());
/*RecipeManager recipeManager = MinecraftServer.getRecipeManager();
ShapelessRecipe shapelessRecipe = new ShapelessRecipe("test", "groupname") {

View File

@ -0,0 +1,33 @@
package fr.themode.demo.commands;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandProcessor;
import net.minestom.server.command.CommandSender;
import net.minestom.server.entity.Player;
/**
* A simple shutdown command
*/
public class ShutdownCommand implements CommandProcessor {
@Override
public String getCommandName() {
return "shutdown";
}
@Override
public String[] getAliases() {
return new String[0];
}
@Override
public boolean process(CommandSender sender, String command, String[] args) {
MinecraftServer.stopCleanly();
return true;
}
@Override
public boolean hasAccess(Player player) {
return player.getPermissionLevel() >= 4;
}
}

View File

@ -80,10 +80,13 @@ public class SchedulerManager {
* Shutdowns all normal tasks and call the registered shutdown tasks
*/
public void shutdown() {
for (Task shutdownTask : this.getShutdownTasks()) {
shutdownTask.schedule();
MinecraftServer.getLOGGER().info("Executing all shutdown tasks..");
for (Task task : this.getShutdownTasks()) {
task.schedule();
}
batchesPool.shutdown();
MinecraftServer.getLOGGER().info("Shutting down the scheduled execution service and batches pool.");
this.timerExecutionService.shutdown();
this.batchesPool.shutdown();
try {
batchesPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {