From ed6d4c77598d385aae96bc2121726fce167c2688 Mon Sep 17 00:00:00 2001 From: Wesley Wolfe Date: Wed, 13 Jun 2012 21:52:49 -0500 Subject: [PATCH] Support asynchronous events; Addresses BUKKIT-1212 --- src/main/java/net/minecraft/server/MinecraftServer.java | 8 +++++--- src/main/java/org/bukkit/craftbukkit/CraftServer.java | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 4ddccac4fa..687932f5fc 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -14,7 +14,6 @@ import java.util.logging.Logger; // CraftBukkit start import java.io.PrintStream; -import java.io.PrintWriter; import java.net.UnknownHostException; import jline.console.ConsoleReader; import joptsimple.OptionSet; @@ -83,6 +82,7 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe public RemoteConsoleCommandSender remoteConsole; public ConsoleReader reader; public static int currentTick; + public final Thread primaryThread; // CraftBukkit end public MinecraftServer(OptionSet options) { // CraftBukkit - adds argument OptionSet @@ -106,6 +106,8 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe } } Runtime.getRuntime().addShutdownHook(new ServerShutdownThread(this)); + + primaryThread = new ThreadServerApplication("Server thread", this); // Moved from main // CraftBukkit end } @@ -625,7 +627,7 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe // CraftBukkit - remove gui - (new ThreadServerApplication("Server thread", minecraftserver)).start(); + minecraftserver.primaryThread.start(); // CraftBukkit - let MinecraftServer construct the thread } catch (Exception exception) { log.log(Level.SEVERE, "Failed to start the minecraft server", exception); } @@ -779,7 +781,7 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe public String[] r() { return (String[]) this.serverConfigurationManager.getBannedPlayers().toArray(new String[0]); } - + public String getServerModName() { return "craftbukkit"; // CraftBukkit - cb > vanilla! } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 00a82f2fbc..708daf7355 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1182,4 +1182,8 @@ public final class CraftServer implements Server { public int getWaterAnimalSpawnLimit() { return waterAnimalSpawn; } + + public boolean isPrimaryThread() { + return Thread.currentThread().equals(console.primaryThread); + } }