From 379d1ed051b025dee4bc512cbf5e49866be6ecf0 Mon Sep 17 00:00:00 2001 From: Kristian Knarvik Date: Tue, 20 Feb 2018 13:39:21 +0100 Subject: [PATCH] Fixes issue #1 --- src/net/knarcraft/serverlauncher/Main.java | 4 +++- .../knarcraft/serverlauncher/server/Server.java | 14 ++++++++++---- .../serverlauncher/userinterface/ServerTab.java | 1 - 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/net/knarcraft/serverlauncher/Main.java b/src/net/knarcraft/serverlauncher/Main.java index 9ebf14b..0eea466 100644 --- a/src/net/knarcraft/serverlauncher/Main.java +++ b/src/net/knarcraft/serverlauncher/Main.java @@ -4,7 +4,6 @@ import net.knarcraft.serverlauncher.profile.Collection; import net.knarcraft.serverlauncher.profile.Profile; import net.knarcraft.serverlauncher.server.Server; import net.knarcraft.serverlauncher.server.ServerType; -import net.knarcraft.serverlauncher.userinterface.GUI; import net.knarcraft.serverlauncher.userinterface.ServerConsoles; import javax.naming.ConfigurationException; @@ -79,6 +78,9 @@ public class Main { } catch (IOException e) { e.printStackTrace(); } + if (!server.getProcess().isAlive()) { + server.stopped(); + } } } } diff --git a/src/net/knarcraft/serverlauncher/server/Server.java b/src/net/knarcraft/serverlauncher/server/Server.java index 62ce791..fbedc83 100644 --- a/src/net/knarcraft/serverlauncher/server/Server.java +++ b/src/net/knarcraft/serverlauncher/server/Server.java @@ -131,6 +131,12 @@ public class Server { return this.playerList; } + public void stopped() { + process = null; + writer = null; + reader = null; + } + /** * @return A representation of the name of a jarfile. */ @@ -298,11 +304,11 @@ public class Server { public String read() throws IOException { String line; - if ((line = reader.readLine()) != null) { - return line; - } else { - return ""; + StringBuilder text = new StringBuilder(); + while (reader.ready() && (line = reader.readLine()) != null) { + text.append(line).append("\n"); } + return text.toString().trim(); } /** diff --git a/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java b/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java index 3723c3e..1bbfba7 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java +++ b/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java @@ -1,6 +1,5 @@ package net.knarcraft.serverlauncher.userinterface; -import net.knarcraft.serverlauncher.Main; import net.knarcraft.serverlauncher.profile.Profile; import net.knarcraft.serverlauncher.server.Server; import net.knarcraft.serverlauncher.server.ServerType;