mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-22 15:22:56 +01:00
Actually shutdown Minestom when MinecraftServer.stopCleanly()
is called
This commit is contained in:
parent
4fb03a8479
commit
82c2af88a0
@ -21,6 +21,7 @@ import net.minestom.server.scoreboard.TeamManager;
|
|||||||
import net.minestom.server.storage.StorageFolder;
|
import net.minestom.server.storage.StorageFolder;
|
||||||
import net.minestom.server.storage.StorageManager;
|
import net.minestom.server.storage.StorageManager;
|
||||||
import net.minestom.server.timer.SchedulerManager;
|
import net.minestom.server.timer.SchedulerManager;
|
||||||
|
import net.minestom.server.utils.thread.MinestomThread;
|
||||||
import net.minestom.server.world.Difficulty;
|
import net.minestom.server.world.Difficulty;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -227,6 +228,10 @@ public class MinecraftServer {
|
|||||||
nettyServer.stop();
|
nettyServer.stop();
|
||||||
schedulerManager.shutdown();
|
schedulerManager.shutdown();
|
||||||
storageManager.getLoadedFolders().forEach(StorageFolder::close);
|
storageManager.getLoadedFolders().forEach(StorageFolder::close);
|
||||||
|
LOGGER.info("Shutting down all thread pools.");
|
||||||
|
MinestomThread.shutdownAll();
|
||||||
|
benchmarkManager.disable();
|
||||||
|
commandManager.stopConsoleThread();
|
||||||
LOGGER.info("Minestom server stopped successfully.");
|
LOGGER.info("Minestom server stopped successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import java.util.*;
|
|||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
|
|
||||||
|
private boolean running;
|
||||||
private String commandPrefix = "/";
|
private String commandPrefix = "/";
|
||||||
|
|
||||||
private ConsoleSender consoleSender = new ConsoleSender();
|
private ConsoleSender consoleSender = new ConsoleSender();
|
||||||
@ -21,18 +22,26 @@ public class CommandManager {
|
|||||||
private Map<String, CommandProcessor> commandProcessorMap = new HashMap<>();
|
private Map<String, CommandProcessor> commandProcessorMap = new HashMap<>();
|
||||||
|
|
||||||
public CommandManager() {
|
public CommandManager() {
|
||||||
|
running = true;
|
||||||
// Setup console thread
|
// Setup console thread
|
||||||
new Thread(() -> {
|
Thread consoleThread = new Thread(() -> {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
while (true) {
|
while (running) {
|
||||||
String command = scanner.nextLine();
|
if(scanner.hasNext()) {
|
||||||
if (!command.startsWith(commandPrefix))
|
String command = scanner.nextLine();
|
||||||
continue;
|
if (!command.startsWith(commandPrefix))
|
||||||
command = command.replaceFirst(commandPrefix, "");
|
continue;
|
||||||
execute(consoleSender, command);
|
command = command.replaceFirst(commandPrefix, "");
|
||||||
|
execute(consoleSender, command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, "ConsoleCommand-Thread").start();
|
}, "ConsoleCommand-Thread");
|
||||||
|
consoleThread.setDaemon(true);
|
||||||
|
consoleThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopConsoleThread() {
|
||||||
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Command<CommandSender> command) {
|
public void register(Command<CommandSender> command) {
|
||||||
|
@ -1,16 +1,30 @@
|
|||||||
package net.minestom.server.utils.thread;
|
package net.minestom.server.utils.thread;
|
||||||
|
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.timer.SchedulerManager;
|
||||||
|
import net.minestom.server.timer.TaskRunnable;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class MinestomThread extends ThreadPoolExecutor {
|
public class MinestomThread extends ThreadPoolExecutor {
|
||||||
|
|
||||||
|
private static final List<MinestomThread> executors = new LinkedList<>();
|
||||||
|
|
||||||
public MinestomThread(int nThreads, String name) {
|
public MinestomThread(int nThreads, String name) {
|
||||||
super(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), r -> {
|
super(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), r -> {
|
||||||
Thread thread = new Thread(r);
|
Thread thread = new Thread(r);
|
||||||
|
thread.setDaemon(true);
|
||||||
thread.setName(thread.getName().replace("Thread", name));
|
thread.setName(thread.getName().replace("Thread", name));
|
||||||
return thread;
|
return thread;
|
||||||
});
|
});
|
||||||
|
executors.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shutdownAll() {
|
||||||
|
executors.forEach(MinestomThread::shutdownNow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user