From 2ac43ce2232d0c9b95276ee48ac6f21340a90323 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Tue, 29 Mar 2011 21:01:04 +0100 Subject: [PATCH] Ctrl+C saves world before stopping --- .../net/minecraft/server/MinecraftServer.java | 4 +++- .../craftbukkit/util/ServerShutdownThread.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 78b18503b7..42b2ba7e99 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -21,6 +21,7 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.LoggerOutputStream; import org.bukkit.craftbukkit.command.ColouredConsoleSender; import org.bukkit.craftbukkit.scheduler.CraftScheduler; +import org.bukkit.craftbukkit.util.ServerShutdownThread; import org.bukkit.event.world.WorldSaveEvent; @@ -64,6 +65,7 @@ public class MinecraftServer implements Runnable, ICommandListener { } catch (IOException ex) { Logger.getLogger(MinecraftServer.class.getName()).log(Level.SEVERE, null, ex); } + Runtime.getRuntime().addShutdownHook(new ServerShutdownThread(this)); // CraftBukkit end } @@ -218,7 +220,7 @@ public class MinecraftServer implements Runnable, ICommandListener { // CraftBukkit end } - private void g() { + public void g() { // Craftbukkit: private -> public a.info("Stopping server"); // CraftBukkit start if (server != null) { diff --git a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java new file mode 100644 index 0000000000..d15bb78273 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java @@ -0,0 +1,17 @@ + +package org.bukkit.craftbukkit.util; + +import net.minecraft.server.MinecraftServer; + +public class ServerShutdownThread extends Thread { + private final MinecraftServer server; + + public ServerShutdownThread(MinecraftServer server) { + this.server = server; + } + + @Override + public void run() { + server.g(); + } +}