From 6692a4c0823ddbee12bf6bd753924e91b1a007e7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 16 Sep 2021 16:58:18 +0200 Subject: [PATCH] Proper waiting for subserver cleanup --- src/de/steamwar/bungeecore/Subserver.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/Subserver.java b/src/de/steamwar/bungeecore/Subserver.java index 6e324f3..b9157c7 100644 --- a/src/de/steamwar/bungeecore/Subserver.java +++ b/src/de/steamwar/bungeecore/Subserver.java @@ -72,6 +72,7 @@ public class Subserver implements Runnable { private final PrintWriter writer; private final ServerInfo server; private final Servertype type; + private final Thread thread; private boolean started; private final List cachedPlayers = new LinkedList<>(); @@ -102,7 +103,8 @@ public class Subserver implements Runnable { serverName, address, "SteamWar.de - Subserver", false); this.writer = new PrintWriter(process.getOutputStream(), true); - ProxyServer.getInstance().getScheduler().runAsync(Persistent.getInstance(), this); + this.thread = new Thread(this, "Subserver " + serverName); + this.thread.start(); } public ServerInfo getServer(){ @@ -133,6 +135,7 @@ public class Subserver implements Runnable { try { if(!process.waitFor(1, TimeUnit.MINUTES)) process.destroy(); + thread.join(); }catch(InterruptedException e){ logger.log(Level.SEVERE, "Subserver stop interrupted!", e); Thread.currentThread().interrupt(); @@ -144,6 +147,7 @@ public class Subserver implements Runnable { if(!process.waitFor(5, TimeUnit.MINUTES) && server.getPlayers().isEmpty()){ process.destroy(); } + thread.join(); }catch(InterruptedException e){ logger.log(Level.SEVERE, "Subserver stop interrupted!", e); Thread.currentThread().interrupt();