diff --git a/server/src/io/anuke/mindustry/server/ServerLauncher.java b/server/src/io/anuke/mindustry/server/ServerLauncher.java index a39ade9f0f..dc2c95b5b6 100644 --- a/server/src/io/anuke/mindustry/server/ServerLauncher.java +++ b/server/src/io/anuke/mindustry/server/ServerLauncher.java @@ -7,14 +7,16 @@ import io.anuke.mindustry.MindustryServer; import io.anuke.mindustry.net.Net; import io.anuke.ucore.util.Log; +import java.lang.reflect.Method; + public class ServerLauncher{ - public static void main(String[] args){ + public static void main(String[] args) throws Exception{ Net.setClientProvider(new KryoClient()); Net.setServerProvider(new KryoServer()); - new HeadlessApplication(new MindustryServer()){ + HeadlessApplication app = new HeadlessApplication(new MindustryServer()){ @Override public boolean executeRunnables() { try { @@ -27,5 +29,29 @@ public class ServerLauncher{ } }; + Method method = app.getClass().getDeclaredMethod("mainLoop"); + method.setAccessible(true); + + //kill default libGDX thread + for(Thread thread : Thread.getAllStackTraces().keySet()){ + if(thread.getName().equals("\"HeadlessApplication\"")){ + thread.interrupt(); + } + } + + //replace it with my own + Thread mainLoopThread = new Thread("HeadlessApplication") { + @Override + public void run () { + try { + method.invoke(app); + } catch (Throwable t) { + t.printStackTrace(); + System.exit(-1); + } + } + }; + mainLoopThread.start(); + } } \ No newline at end of file