From 28bb51be35ecbb0a294daeb04973f8a7389d4dcf Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Jan 2020 18:29:43 +0100 Subject: [PATCH 1/2] Adding new serverstart option for startup change --- src/de/steamwar/bungeecore/Subserver.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/Subserver.java b/src/de/steamwar/bungeecore/Subserver.java index 797de0c..7df9b1f 100644 --- a/src/de/steamwar/bungeecore/Subserver.java +++ b/src/de/steamwar/bungeecore/Subserver.java @@ -52,20 +52,22 @@ public class Subserver implements Runnable { } public Subserver(Servertype type, String serverName, int port, Runnable shutdownCallback, String... command){ + this(type, serverName, port, new ProcessBuilder(command), shutdownCallback); + } + + public Subserver(Servertype type, String serverName, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){ this.started = false; this.serverName = serverName; this.type = type; this.shutdownCallback = shutdownCallback; - ProcessBuilder pb = new ProcessBuilder(command); - InetSocketAddress address = new InetSocketAddress("127.0.0.1", port); - try{ - this.p = pb.start(); + this.p = processBuilder.start(); }catch(IOException e){ throw new SecurityException("Server could not be started", e); } + InetSocketAddress address = new InetSocketAddress("127.0.0.1", port); this.server = ProxyServer.getInstance().constructServerInfo( serverName, address, "SteamWar.de - Subserver", false); this.writer = new PrintWriter(p.getOutputStream(), true); From 8c99597bdd1f0bf947e8509a650a5e49ab54d870 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 10 Jan 2020 15:59:10 +0100 Subject: [PATCH 2/2] Renaming process --- src/de/steamwar/bungeecore/Subserver.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/Subserver.java b/src/de/steamwar/bungeecore/Subserver.java index 7df9b1f..8598d00 100644 --- a/src/de/steamwar/bungeecore/Subserver.java +++ b/src/de/steamwar/bungeecore/Subserver.java @@ -39,7 +39,7 @@ public class Subserver implements Runnable { private final String serverName; private final Runnable shutdownCallback; - private final Process p; + private final Process process; private final PrintWriter writer; private final ServerInfo server; private final Servertype type; @@ -62,7 +62,7 @@ public class Subserver implements Runnable { this.shutdownCallback = shutdownCallback; try{ - this.p = processBuilder.start(); + this.process = processBuilder.start(); }catch(IOException e){ throw new SecurityException("Server could not be started", e); } @@ -70,7 +70,7 @@ public class Subserver implements Runnable { InetSocketAddress address = new InetSocketAddress("127.0.0.1", port); this.server = ProxyServer.getInstance().constructServerInfo( serverName, address, "SteamWar.de - Subserver", false); - this.writer = new PrintWriter(p.getOutputStream(), true); + this.writer = new PrintWriter(process.getOutputStream(), true); ProxyServer.getInstance().getScheduler().runAsync(Persistent.getInstance(), this); } @@ -94,8 +94,8 @@ public class Subserver implements Runnable { public void stop(){ writer.println("stop"); try { - if(!p.waitFor(1, TimeUnit.MINUTES)) - p.destroy(); + if(!process.waitFor(1, TimeUnit.MINUTES)) + process.destroy(); }catch(InterruptedException e){ logger.log(Level.SEVERE, "Subserver stop interrupted!", e); Thread.currentThread().interrupt(); @@ -124,7 +124,7 @@ public class Subserver implements Runnable { ProxyServer.getInstance().getServers().put(serverName, server); serverList.add(this); - try(BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))){ + try(BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))){ String line = ""; while (!started && (line = reader.readLine()) != null) { started = line.contains("ViaVersion detected server version"); @@ -144,7 +144,7 @@ public class Subserver implements Runnable { } cachedPlayers.clear(); - p.waitFor(); + process.waitFor(); } catch(IOException e) { logger.log(Level.SEVERE, "Server " + serverName + " was interrupted!", e); fatalError();