Fixes a bug where Custom would always cause an exception on save
This commit is contained in:
parent
fd65b46ea2
commit
27024d7b8f
3
.gitignore
vendored
3
.gitignore
vendored
@ -27,4 +27,5 @@ hs_err_pid*
|
||||
*.xml
|
||||
*.iml
|
||||
|
||||
bin/
|
||||
bin/
|
||||
*.txt
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user