Improved checking for abnormally closed servers
This commit is contained in:
parent
3e7c69d7a2
commit
2ff3c765a6
@ -83,6 +83,22 @@ public class Main {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!serversRunning()) {
|
||||
Profile.getGUI().stopped();
|
||||
Profile.getGUI().setStatus("Servers are stopped");
|
||||
} else {
|
||||
Profile.getGUI().running();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean serversRunning() {
|
||||
int num = 0;
|
||||
for (Collection collection : Profile.getCurrent().getCollections()) {
|
||||
if (collection.getServer().isStarted() || (collection.getServer().getProcess() != null && collection.getServer().getProcess().isAlive())) {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,6 +41,7 @@ public class Server {
|
||||
private String snapshotVersion;
|
||||
private String spongeVanillaVersion;
|
||||
private String bungeeVersion;
|
||||
private boolean started;
|
||||
|
||||
public Server(String name) {
|
||||
this.name = name;
|
||||
@ -88,6 +89,10 @@ public class Server {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return this.type.getName();
|
||||
}
|
||||
@ -136,6 +141,7 @@ public class Server {
|
||||
process = null;
|
||||
writer = null;
|
||||
reader = null;
|
||||
started = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,6 +234,7 @@ public class Server {
|
||||
}
|
||||
server.writer.flush();
|
||||
server.writer = null;
|
||||
server.started = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -240,6 +247,13 @@ public class Server {
|
||||
for (Collection collection : Profile.getCurrent().getCollections()) {
|
||||
if (!collection.getServer().run()) {
|
||||
Profile.getGUI().setStatus("An error occurred. Start aborted");
|
||||
try {
|
||||
Server.stop();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Profile.getGUI().stopped();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -249,6 +263,7 @@ public class Server {
|
||||
*/
|
||||
private boolean run() {
|
||||
if (this.enabled) {
|
||||
this.started = true;
|
||||
if (!Profile.getCurrent().getDownloadJars()) {
|
||||
try {
|
||||
Profile.getGUI().setStatus("Downloading jar...");
|
||||
@ -257,6 +272,7 @@ public class Server {
|
||||
} catch (FileNotFoundException e) {
|
||||
Profile.getGUI().setStatus("Error: Jar file not found");
|
||||
e.printStackTrace();
|
||||
this.started = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -265,6 +281,8 @@ public class Server {
|
||||
TimeUnit.SECONDS.sleep(Profile.getCurrent().getDelayStartup());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
this.started = false;
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ProcessBuilder builder;
|
||||
@ -299,12 +317,15 @@ public class Server {
|
||||
InputStream stdout = this.process.getInputStream();
|
||||
this.reader = new BufferedReader (new InputStreamReader(stdout));
|
||||
Profile.getGUI().setStatus("Servers are running");
|
||||
this.started = true;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Profile.getGUI().setStatus("Could not start server");
|
||||
this.started = false;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
this.started = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -409,6 +409,7 @@ public class GUI implements ActionListener {
|
||||
trayIcon = new TrayIcon(trayImage, "Minecraft Server Launcher", popup);
|
||||
trayIcon.setImageAutoSize(true);
|
||||
ActionListener exitListener= e -> {
|
||||
stop();
|
||||
try {
|
||||
Profile.getCurrent().save();
|
||||
} catch (FileNotFoundException e1) {
|
||||
@ -445,12 +446,12 @@ public class GUI implements ActionListener {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
stop();
|
||||
try {
|
||||
Profile.getCurrent().save();
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
stop();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@ -509,8 +510,6 @@ public class GUI implements ActionListener {
|
||||
background();
|
||||
} else if (e.getSource() == chckbxmntmDelayStartup) {
|
||||
delay();
|
||||
} else if (e.getSource() == targetServer) {
|
||||
updatePlayers();
|
||||
} else if (e.getSource() == chckbxmntmDownloadJars) {
|
||||
downloadJars();
|
||||
} else if (e.getSource() == mntmErrors) {
|
||||
@ -616,9 +615,25 @@ public class GUI implements ActionListener {
|
||||
}
|
||||
} else if (e.getSource() == btnServerConsoles) {
|
||||
ServerConsoles.show();
|
||||
} else if (e.getSource() == targetServer) {
|
||||
updatePlayers();
|
||||
}
|
||||
}
|
||||
|
||||
public void running() {
|
||||
profiles.setEnabled(false);
|
||||
addProfile.setEnabled(false);
|
||||
delProfile.setEnabled(false);
|
||||
btnStartServer.setEnabled(false);
|
||||
}
|
||||
|
||||
public void stopped() {
|
||||
profiles.setEnabled(true);
|
||||
addProfile.setEnabled(true);
|
||||
delProfile.setEnabled(true);
|
||||
btnStartServer.setEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the previous profile and loads data from the new profile.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user