diff --git a/.gitignore b/.gitignore index e55848e..11f4211 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,5 @@ hs_err_pid* *.xml *.iml -bin/ \ No newline at end of file +bin/ +*.txt \ No newline at end of file diff --git a/src/net/knarcraft/serverlauncher/profile/Profile.java b/src/net/knarcraft/serverlauncher/profile/Profile.java index 4181893..9a36cef 100644 --- a/src/net/knarcraft/serverlauncher/profile/Profile.java +++ b/src/net/knarcraft/serverlauncher/profile/Profile.java @@ -188,7 +188,11 @@ public class Profile { server.setPath(serverTab.getPath()); server.setMaxRam(serverTab.getMaxRam()); server.setType(ServerType.getByName(serverTab.getType())); - server.setServerVersion(serverTab.getVersion()); + try { + server.setServerVersion(serverTab.getVersion()); + } catch (IllegalArgumentException e) { + JOptionPane.showMessageDialog(null, "Invalid server version for " + server.getName(), "Error", JOptionPane.ERROR_MESSAGE); + } server.toggle(serverTab.enabled()); } StringBuilder saveString = new StringBuilder(String.format("%s;%b;%b;%b?", this.name, this.runInBackground, this.delayStartup, this.downloadJars)); @@ -198,7 +202,7 @@ public class Profile { saveString.append(String.format("%s;%s;%b;%s;%s;%s;%s;%s;%s;%s!", server.getName(), server.getPath(), server.isEnabled(), server.typeName(), server.getServerVersion(), server.getMaxRam(), server.getVanillaVersion(), server.getSnapshotVersion(), server.getSpongeVanillaVersion(), server.getBungeeVersion())); } saveString = new StringBuilder(saveString.substring(0, saveString.length() - 1)); - try (PrintWriter file = new PrintWriter("Profiles.txt")) { + try (PrintWriter file = new PrintWriter("files/Profiles.txt")) { file.println(saveString); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(null, "Unable to save to file. Try running the software as an administrator.", "About", JOptionPane.INFORMATION_MESSAGE); diff --git a/src/net/knarcraft/serverlauncher/server/Server.java b/src/net/knarcraft/serverlauncher/server/Server.java index 834becf..1b14283 100644 --- a/src/net/knarcraft/serverlauncher/server/Server.java +++ b/src/net/knarcraft/serverlauncher/server/Server.java @@ -191,14 +191,18 @@ public class Server { * @param serverVersion Version number. */ public void setServerVersion(String serverVersion) throws IllegalArgumentException { - String[] versions = this.type.getVersions(); - for (String version : versions) { - if (version.equals(serverVersion)) { - this.serverVersion = serverVersion; - return; + if (this.type.getName().equals("Custom")) { + this.serverVersion = serverVersion; + } else { + String[] versions = this.type.getVersions(); + for (String version : versions) { + if (version.equals(serverVersion)) { + this.serverVersion = serverVersion; + return; + } } + throw new IllegalArgumentException("Invalid server version."); } - throw new IllegalArgumentException("Invalid server version."); } /** @@ -385,7 +389,7 @@ public class Server { * @param version The version string */ private void setVersion(String type, String version) { - if (!version.equals("")) { + if (!type.equals("")) { switch (type) { case "Vanilla": this.vanillaVersion = version;