Implemented the autoStart feature into the ServerManager

This commit is contained in:
Mathias Wagner 2024-02-13 18:51:14 +01:00
parent 36b59f8316
commit 677bde3c82
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44
3 changed files with 39 additions and 1 deletions

View File

@ -42,8 +42,10 @@ public class ServerManager {
servers.forEach(server -> {
if (server.getStatus() == ServerStatus.ONLINE) return;
startServer(server);
if (server.getConfiguration().isAutoStart()) startServer(server);
});
LOG.info("All servers have been started");
}
/**

View File

@ -17,6 +17,7 @@ public class ServerConfiguration {
private String version;
private String description;
private int memory;
private boolean autoStart;
/**
* Loads a server configuration from a file
@ -101,6 +102,14 @@ public class ServerConfiguration {
return memory;
}
/**
* Gets the auto start of the server
* @return The auto start of the server
*/
public boolean isAutoStart() {
return autoStart;
}
/**
* Sets the description of the server
*
@ -150,4 +159,13 @@ public class ServerConfiguration {
this.name = name;
save();
}
/**
* Sets the auto start of the server
* @param autoStart The new auto start of the server
*/
public void setAutoStart(boolean autoStart) {
this.autoStart = autoStart;
save();
}
}

View File

@ -0,0 +1,18 @@
package de.gnmyt.mcdash.routes.server;
import de.gnmyt.mcdash.handler.DefaultHandler;
import de.gnmyt.mcdash.http.Request;
import de.gnmyt.mcdash.http.ResponseController;
public class ServerStartRoute extends DefaultHandler {
@Override
public String path() {
return "start";
}
@Override
public void post(Request request, ResponseController response) throws Exception {
response.text("The server is already running");
}
}