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 snapshotVersion;
|
||||||
private String spongeVanillaVersion;
|
private String spongeVanillaVersion;
|
||||||
private String bungeeVersion;
|
private String bungeeVersion;
|
||||||
|
private boolean started;
|
||||||
|
|
||||||
public Server(String name) {
|
public Server(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -88,6 +89,10 @@ public class Server {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isStarted() {
|
||||||
|
return started;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTypeName() {
|
public String getTypeName() {
|
||||||
return this.type.getName();
|
return this.type.getName();
|
||||||
}
|
}
|
||||||
@ -136,6 +141,7 @@ public class Server {
|
|||||||
process = null;
|
process = null;
|
||||||
writer = null;
|
writer = null;
|
||||||
reader = null;
|
reader = null;
|
||||||
|
started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -228,6 +234,7 @@ public class Server {
|
|||||||
}
|
}
|
||||||
server.writer.flush();
|
server.writer.flush();
|
||||||
server.writer = null;
|
server.writer = null;
|
||||||
|
server.started = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,6 +247,13 @@ public class Server {
|
|||||||
for (Collection collection : Profile.getCurrent().getCollections()) {
|
for (Collection collection : Profile.getCurrent().getCollections()) {
|
||||||
if (!collection.getServer().run()) {
|
if (!collection.getServer().run()) {
|
||||||
Profile.getGUI().setStatus("An error occurred. Start aborted");
|
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() {
|
private boolean run() {
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
|
this.started = true;
|
||||||
if (!Profile.getCurrent().getDownloadJars()) {
|
if (!Profile.getCurrent().getDownloadJars()) {
|
||||||
try {
|
try {
|
||||||
Profile.getGUI().setStatus("Downloading jar...");
|
Profile.getGUI().setStatus("Downloading jar...");
|
||||||
@ -257,6 +272,7 @@ public class Server {
|
|||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Profile.getGUI().setStatus("Error: Jar file not found");
|
Profile.getGUI().setStatus("Error: Jar file not found");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
this.started = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,6 +281,8 @@ public class Server {
|
|||||||
TimeUnit.SECONDS.sleep(Profile.getCurrent().getDelayStartup());
|
TimeUnit.SECONDS.sleep(Profile.getCurrent().getDelayStartup());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
this.started = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ProcessBuilder builder;
|
ProcessBuilder builder;
|
||||||
@ -299,12 +317,15 @@ public class Server {
|
|||||||
InputStream stdout = this.process.getInputStream();
|
InputStream stdout = this.process.getInputStream();
|
||||||
this.reader = new BufferedReader (new InputStreamReader(stdout));
|
this.reader = new BufferedReader (new InputStreamReader(stdout));
|
||||||
Profile.getGUI().setStatus("Servers are running");
|
Profile.getGUI().setStatus("Servers are running");
|
||||||
|
this.started = true;
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Profile.getGUI().setStatus("Could not start server");
|
Profile.getGUI().setStatus("Could not start server");
|
||||||
|
this.started = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
this.started = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,6 +409,7 @@ public class GUI implements ActionListener {
|
|||||||
trayIcon = new TrayIcon(trayImage, "Minecraft Server Launcher", popup);
|
trayIcon = new TrayIcon(trayImage, "Minecraft Server Launcher", popup);
|
||||||
trayIcon.setImageAutoSize(true);
|
trayIcon.setImageAutoSize(true);
|
||||||
ActionListener exitListener= e -> {
|
ActionListener exitListener= e -> {
|
||||||
|
stop();
|
||||||
try {
|
try {
|
||||||
Profile.getCurrent().save();
|
Profile.getCurrent().save();
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
@ -445,12 +446,12 @@ public class GUI implements ActionListener {
|
|||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
stop();
|
||||||
try {
|
try {
|
||||||
Profile.getCurrent().save();
|
Profile.getCurrent().save();
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
stop();
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -509,8 +510,6 @@ public class GUI implements ActionListener {
|
|||||||
background();
|
background();
|
||||||
} else if (e.getSource() == chckbxmntmDelayStartup) {
|
} else if (e.getSource() == chckbxmntmDelayStartup) {
|
||||||
delay();
|
delay();
|
||||||
} else if (e.getSource() == targetServer) {
|
|
||||||
updatePlayers();
|
|
||||||
} else if (e.getSource() == chckbxmntmDownloadJars) {
|
} else if (e.getSource() == chckbxmntmDownloadJars) {
|
||||||
downloadJars();
|
downloadJars();
|
||||||
} else if (e.getSource() == mntmErrors) {
|
} else if (e.getSource() == mntmErrors) {
|
||||||
@ -555,12 +554,12 @@ public class GUI implements ActionListener {
|
|||||||
} else if (e.getSource() == mntmStory) {
|
} else if (e.getSource() == mntmStory) {
|
||||||
goToURL("https://knarcraft.net/Bungeeminecraftserverlauncher/Story/");
|
goToURL("https://knarcraft.net/Bungeeminecraftserverlauncher/Story/");
|
||||||
} else if (e.getSource() == btnStartServer) {
|
} else if (e.getSource() == btnStartServer) {
|
||||||
try {
|
try {
|
||||||
Profile.getCurrent().save();
|
Profile.getCurrent().save();
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
Executors.newSingleThreadExecutor().execute(Server::startServers);
|
Executors.newSingleThreadExecutor().execute(Server::startServers);
|
||||||
} else if (e.getSource() == btnStopServer) {
|
} else if (e.getSource() == btnStopServer) {
|
||||||
stop();
|
stop();
|
||||||
} else if (e.getSource() == addServer) {
|
} else if (e.getSource() == addServer) {
|
||||||
@ -580,11 +579,11 @@ public class GUI implements ActionListener {
|
|||||||
updateProfiles();
|
updateProfiles();
|
||||||
}
|
}
|
||||||
} else if (e.getSource() == profiles) {
|
} else if (e.getSource() == profiles) {
|
||||||
try {
|
try {
|
||||||
changeProfile();
|
changeProfile();
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
} else if (e.getSource() == btnKick) {
|
} else if (e.getSource() == btnKick) {
|
||||||
if (selectedServerValue != null && selectedPlayerValue != null) {
|
if (selectedServerValue != null && selectedPlayerValue != null) {
|
||||||
Profile.getCurrent().sendCommand(selectedServerValue, "kick " + selectedPlayerValue);
|
Profile.getCurrent().sendCommand(selectedServerValue, "kick " + selectedPlayerValue);
|
||||||
@ -616,9 +615,25 @@ public class GUI implements ActionListener {
|
|||||||
}
|
}
|
||||||
} else if (e.getSource() == btnServerConsoles) {
|
} else if (e.getSource() == btnServerConsoles) {
|
||||||
ServerConsoles.show();
|
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.
|
* Saves the previous profile and loads data from the new profile.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user