Stop the server on Ctrl+C and SIGINT signal

This commit is contained in:
Lorenzo Lapucci 2021-08-22 14:12:38 +02:00
parent a8d90955c7
commit c61a3dcd12
2 changed files with 6 additions and 1 deletions

View File

@ -700,6 +700,9 @@ public final class MinecraftServer {
if (terminalEnabled) {
MinestomTerminal.start();
}
// Stop the server on SIGINT
Runtime.getRuntime().addShutdownHook(new Thread(MinecraftServer::stopCleanly));
}
/**

View File

@ -39,7 +39,9 @@ public class MinestomTerminal {
command = reader.readLine(PROMPT);
COMMAND_MANAGER.execute(COMMAND_MANAGER.getConsoleSender(), command);
} catch (UserInterruptException e) {
// Ignore
// Handle Ctrl + C
System.exit(0);
return;
} catch (EndOfFileException e) {
return;
}