Fix cli errors when using ctrl+c to stop

This commit is contained in:
Lukas Rieger (Blue) 2024-06-25 20:46:30 +02:00
parent f42ebdbc79
commit 458daaa325
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6

View File

@ -68,9 +68,12 @@
public class BlueMapCLI { public class BlueMapCLI {
private static boolean shutdownInProgress = false;
private String minecraftVersion = null; private String minecraftVersion = null;
private Path configFolder = Path.of("config"); private Path configFolder = Path.of("config");
public void renderMaps(BlueMapService blueMap, boolean watch, Predicate<TileState> force, boolean forceGenerateWebapp, public void renderMaps(BlueMapService blueMap, boolean watch, Predicate<TileState> force, boolean forceGenerateWebapp,
@Nullable String mapsToRender) throws ConfigurationException, IOException, InterruptedException { @Nullable String mapsToRender) throws ConfigurationException, IOException, InterruptedException {
@ -190,7 +193,10 @@ public void run() {
Logger.global.logInfo("Stopped."); Logger.global.logInfo("Stopped.");
}; };
Thread shutdownHook = new Thread(shutdown, "BlueMap-CLI-ShutdownHook"); Thread shutdownHook = new Thread(() -> {
shutdownInProgress = true;
shutdown.run();
}, "BlueMap-CLI-ShutdownHook");
Runtime.getRuntime().addShutdownHook(shutdownHook); Runtime.getRuntime().addShutdownHook(shutdownHook);
//metrics report //metrics report
@ -201,6 +207,8 @@ public void run() {
// wait until done, then shutdown if not watching // wait until done, then shutdown if not watching
renderManager.awaitIdle(); renderManager.awaitIdle();
if (shutdownInProgress) return;
Logger.global.logInfo("Your maps are now all up-to-date!"); Logger.global.logInfo("Your maps are now all up-to-date!");
if (watch) { if (watch) {