diff --git a/Main.java b/Main.java index 45e3dcf..92ebff1 100644 --- a/Main.java +++ b/Main.java @@ -1,21 +1,49 @@ import java.lang.Runtime; import java.util.ArrayList; +import java.net.URL; +import java.util.Scanner; public class Main { - public ArrayList servers; + public ArrayList servers = new ArrayList(); + public ArrayList serverTypes = new ArrayList(); + + private final BASEURL = "https://knarcraft.net/Api/Download/bungeeminecraftserverlauncher/jars"; + private final BUKKITURL = BASEURL + "/Bukkit/"; + private final MCPCURL = BASEURL + "/MCPC+/"; + private final SPIGOT = BASEURL + "/Spigot/"; public static void main(String[] args) { - + addServerTypes(); + } + + public static void addServerTypes() { + serverTypes.add(new ServerType("Vanilla", {"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", {"Latest"})); + serverTypes.add(new ServerType("SpongeVanilla", {"1.11.2", "1.10.2", "1.8.9"})); + serverTypes.add(new ServerType("Spigot", {"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", {"1.6.4", "1.6.2", "1.5.2", "1.4.7"})); + serverTypes.add(new ServerType("Craftbukkit", {"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", {""})); } public static void startServers() { for (Server server : servers) { if (server.isEnabled()) { String path = server.getPath(); - ServerType = this.type; - + String type = server.getType(); + String ram = server.maxRam(); Runtime rt = Runtime.getRuntime(); - Process pr = rt.exec("java -Xmx" + $MemoryValue + " -Xms512M -jar " + '"' + $loc + "\\" + $Type + '" nogui'); + Process pr = rt.exec("java -Xmx" + ram + " -Xms512M -jar " + '"' + path + "\\" + type + '" nogui'); } } } + + public static void readFile(String path) { + try { + URL url = new URL(path); + Scanner s = new Scanner(url.openStream()); + System.out.println(s.next()); + } catch (java.io.IOException e) { + System.out.println(e); + } + } } \ No newline at end of file diff --git a/README.md b/README.md index 0535767..7b05f0a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # Minecraft-Server-Launcher -I originally created this software in 2013 using AutoIt. Since I am now learning Java, and I have wanted to rewrite it for a long time, I am trying to recreate it in Java. It is currently missing mostly everything, but it's nothing a lot of work can't fix. \ No newline at end of file +I originally created this software in 2013 using AutoIt. Since I am now learning Java, and I have wanted to rewrite it for a long time, I am trying to recreate it in Java. It is currently missing mostly everything, but it's nothing a lot of work can't fix. +The original version can be found at: https://knarcraft.net/Downloads/Bungeeminecraftserverlauncher/ +Its goal is to do everything the original does, just better. The original is 1595 lines of code repetition and dirty code. I had no prior programming experience when I first started working on the original, which is why it became such a mess. \ No newline at end of file diff --git a/Server.java b/Server.java index 77f8db7..9b90aba 100644 --- a/Server.java +++ b/Server.java @@ -1,11 +1,13 @@ import java.util.ArrayList; public class Server { + private static String[17] ramList = {"512M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G", "10G", "11G", "12G", "13G", "14G", "15G", "16G"}; private String name; private String path; private boolean enabled; private ArrayList playerList; private ServerType type; private String serverVersion; + private String maxRam; public Server(String name) { this.name = name; @@ -14,6 +16,7 @@ public class Server { this.playerList = new ArrayList(); this.type = null; this.serverVersion = null; + this.maxRam = ramList[0]; } public void addPlayer(String name) { @@ -33,17 +36,15 @@ public class Server { return this.path; } - public ServerType getType() { - return this.type; - } - - public String getVersion() { - return this.version; + public String getType() { + return this.type.getName() + this.version; } public boolean isEnabled() { return this.enabled; } - + public String maxRam() { + return this.maxRam; + } } \ No newline at end of file diff --git a/ServerType.java b/ServerType.java index 9b12c80..7203de2 100644 --- a/ServerType.java +++ b/ServerType.java @@ -1,8 +1,8 @@ public class ServerType { private String name; - private ArrayList versions; + private String[] versions; - public ServerType(String name, ArrayList versions) { + public ServerType(String name, String[] versions) { this.name = name; this.versions = versions; } @@ -14,8 +14,4 @@ public class ServerType { public ArrayList getVersions() { return this.versions; } - - public boolean validVersion() { - - } } \ No newline at end of file