Merge pull request #427 from AlexDicy/master

Handle Ctrl+C and SIGINT signal
This commit is contained in:
TheMode 2021-08-22 14:28:18 +02:00 committed by GitHub
commit 01e39b5d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
}