2018-01-24 12:18:06 +01:00
|
|
|
import net.knarcraft.serverlauncher.server.*;
|
2018-01-23 23:39:37 +01:00
|
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.lang.Runtime;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.io.IOException;
|
|
|
|
//Java 9 required.
|
2018-01-24 12:18:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A software for managing Minecraft servers.
|
|
|
|
* @author Kristian Knarvik
|
|
|
|
*/
|
2018-01-23 23:39:37 +01:00
|
|
|
public class Main {
|
|
|
|
private static ArrayList<Server> servers = new ArrayList<>();
|
|
|
|
private static ArrayList<ServerType> serverTypes = new ArrayList<>();
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
addServerTypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Add gui
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds all the valid server types and versions.
|
|
|
|
*/
|
|
|
|
private static void addServerTypes() {
|
|
|
|
//This could be changed to read from a list which is downloaded to the user's computer.
|
|
|
|
serverTypes.add(new ServerType("Vanilla", new String[]{"Latest", "1.12", "1.11.2", "1.10.2", "1.9.4", "1.8.9", "1.7.10", "1.6.4", "1.5.2", "1.4.7", "1.3.2", "1.2.5"}));
|
|
|
|
serverTypes.add(new ServerType("Snapshot", new String[]{"Latest"}));
|
2018-01-24 21:33:14 +01:00
|
|
|
serverTypes.add(new AdvancedServerType("SpongeVanilla", new String[]{"1.11.2", "1.10.2", "1.8.9"}, "https://dl-api.spongepowered.org/v1/org.spongepowered/spongevanilla/downloads?type=stable&minecraft=", "\"version\":\"", "\",", "https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/", "/spongevanilla-"));
|
2018-01-23 23:39:37 +01:00
|
|
|
serverTypes.add(new ServerType("Spigot", new String[]{"1.12", "1.11.2", "1.10.2", "1.9.4", "1.9", "1.8.8", "1.7.10", "1.6.4", "1.5.2", "1.4.7"}));
|
|
|
|
serverTypes.add(new ServerType("MCPCplus", new String[]{"1.6.4", "1.6.2", "1.5.2", "1.4.7"}));
|
|
|
|
serverTypes.add(new ServerType("Craftbukkit", new String[]{"1.12", "1.11.2", "1.10.2", "1.9.4", "1.8.8", "1.7.10", "1.6.4", "1.5.2", "1.4.6", "1.3.2", "1.2.5", "1.1", "1.0"}));
|
|
|
|
serverTypes.add(new ServerType("Custom", new String[]{""}));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs all enabled servers with their settings.
|
|
|
|
*/
|
|
|
|
public static void startServers() {
|
|
|
|
//This should update the server status to running. The output should display in a custom commandline interface.
|
|
|
|
for (Server server : servers) {
|
|
|
|
if (server.isEnabled()) {
|
|
|
|
String path = server.getPath();
|
|
|
|
String type = server.getType();
|
|
|
|
try {
|
|
|
|
server.downloadJar();
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
System.out.println("File was not found.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String ram = server.maxRam();
|
|
|
|
Runtime rt = Runtime.getRuntime();
|
|
|
|
try {
|
|
|
|
Process pr = rt.exec("java -Xmx" + ram + " -Xms512M -jar " + "\"" + path + "\\" + type + "\" nogui");
|
|
|
|
long pid = pr.pid();
|
|
|
|
server.updatePid(pid);
|
|
|
|
System.out.println("Success");
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|