Kristian Knarvik
0c2c26e153
More comments are added. More work on downloading server jars is done. Server test added.
76 lines
4.4 KiB
Java
76 lines
4.4 KiB
Java
import net.knarcraft.serverlauncher.server.*;
|
|
|
|
import java.io.*;
|
|
import java.util.ArrayList;
|
|
|
|
public class ServerTest {
|
|
private static ArrayList<ServerType> serverTypes = new ArrayList<>();
|
|
private static ArrayList<Server> servers = new ArrayList<>();
|
|
public static void main(String[] args) {
|
|
addServerTypes();
|
|
Server server1 = new Server("Server1");
|
|
server1.toggle();
|
|
server1.setPath("C:\\Users\\Kristian\\Desktop\\Test");
|
|
server1.setType((AdvancedServerType) serverTypes.get(0));
|
|
server1.setServerVersion("Latest");
|
|
server1.setMaxRam("1G");
|
|
servers.add(server1);
|
|
startServers(servers);
|
|
}
|
|
|
|
|
|
/**
|
|
* 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 AdvancedServerType("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"}, "https://launchermeta.mojang.com/mc/game/version_manifest.json", "\"release\":\"", "\"", "https://s3.amazonaws.com/Minecraft.Download/versions/", "/minecraft_server."));
|
|
serverTypes.add(new AdvancedServerType("Snapshot", new String[]{"Latest"}, "https://launchermeta.mojang.com/mc/game/version_manifest.json", "\"snapshot\":\"", "\"", "https://s3.amazonaws.com/Minecraft.Download/versions/", "/minecraft_server."));
|
|
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-"));
|
|
serverTypes.add(new AdvancedServerType("Bungee", new String[]{"Latest"}, "https://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/", "Artifacts of BungeeCord #", " ", "http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/BungeeCord.jar", ""));
|
|
serverTypes.add(new ServerType("Spigot", new String[]{"1.12.2", "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"}, "https://knarcraft.net/Api/Download/bungeeminecraftserverlauncher/jars/Spigot/"));
|
|
serverTypes.add(new ServerType("MCPCplus", new String[]{"1.6.4", "1.6.2", "1.5.2", "1.4.7"}, "https://knarcraft.net/Api/Download/bungeeminecraftserverlauncher/jars/MCPC+/"));
|
|
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"}, "https://knarcraft.net/Api/Download/bungeeminecraftserverlauncher/jars/Bukkit/"));
|
|
serverTypes.add(new ServerType("Custom", new String[]{""}, ""));
|
|
}
|
|
|
|
/**
|
|
* Runs all enabled servers with their settings.
|
|
*/
|
|
public static void startServers(ArrayList<Server> servers) {
|
|
System.out.println("Starting servers.");
|
|
for (Server server : servers) {
|
|
if (server.isEnabled()) {
|
|
String path = server.getPath();
|
|
String type = server.getType();
|
|
/* try {
|
|
server.downloadJar();
|
|
System.out.println("File downloaded.");
|
|
} 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 + "\"", null, new File(server.getPath()));
|
|
String line;
|
|
BufferedReader in = new BufferedReader(
|
|
new InputStreamReader(pr.getInputStream()) );
|
|
while ((line = in.readLine()) != null) {
|
|
System.out.println(line);
|
|
}
|
|
in.close();
|
|
long pid = pr.pid();
|
|
server.updatePid(pid);
|
|
System.out.println("Success");
|
|
} catch (IOException e) {
|
|
System.out.println("Error");
|
|
}
|
|
} else {
|
|
System.out.println("Server disabled");
|
|
}
|
|
}
|
|
}
|
|
}
|