Fixes a bug where Custom would always cause an exception on save

This commit is contained in:
Kristian Knarvik 2018-02-03 13:02:37 +01:00
parent fd65b46ea2
commit 27024d7b8f
3 changed files with 19 additions and 10 deletions

1
.gitignore vendored
View File

@ -28,3 +28,4 @@ hs_err_pid*
*.iml
bin/
*.txt

View File

@ -188,7 +188,11 @@ public class Profile {
server.setPath(serverTab.getPath());
server.setMaxRam(serverTab.getMaxRam());
server.setType(ServerType.getByName(serverTab.getType()));
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);

View File

@ -191,6 +191,9 @@ public class Server {
* @param serverVersion Version number.
*/
public void setServerVersion(String serverVersion) throws IllegalArgumentException {
if (this.type.getName().equals("Custom")) {
this.serverVersion = serverVersion;
} else {
String[] versions = this.type.getVersions();
for (String version : versions) {
if (version.equals(serverVersion)) {
@ -200,6 +203,7 @@ public class Server {
}
throw new IllegalArgumentException("Invalid server version.");
}
}
/**
* Runs all enabled servers with their settings.
@ -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;