Fixes casting problems

This commit is contained in:
2018-01-25 19:55:28 +01:00
parent 5e4b956e19
commit 7843331605
3 changed files with 63 additions and 61 deletions

View File

@ -18,7 +18,7 @@ public class Server {
private String path;
private boolean enabled;
private ArrayList<String> playerList;
private AdvancedServerType type;
private ServerType type;
private String serverVersion;
private String maxRam;
private long pid;
@ -71,7 +71,7 @@ public class Server {
this.path = path;
}
public void setType(AdvancedServerType type) {
public void setType(ServerType type) {
this.type = type;
}
@ -127,6 +127,7 @@ public class Server {
* @throws FileNotFoundException if the file was not found and could not be acquired.
*/
public void downloadJar() throws FileNotFoundException {
AdvancedServerType type;
File file = new File(this.path + "\\" + this.getType());
Path filePath = Paths.get(this.path + "\\" + this.getType());
String versionText;
@ -142,7 +143,7 @@ public class Server {
case "Craftbukkit":
case "MCPCplus":
if (!file.isFile()) {
success = downloadFile(type.getDownloadURL() + type.getName() + this.serverVersion + ".jar", filePath);
success = downloadFile(this.type.getDownloadURL() + this.type.getName() + this.serverVersion + ".jar", filePath);
if (!success) {
throw new FileNotFoundException("Jar file could not be downloaded.");
}
@ -150,21 +151,22 @@ public class Server {
break;
case "Vanilla":
case "Snapshot":
type = (AdvancedServerType) this.type;
if (this.serverVersion.equals("Latest")) {
try {
versionText = readFile(this.type.getVersionURL());
versionText = readFile(type.getVersionURL());
} catch (IOException e) {
throw new FileNotFoundException("Version file could not be downloaded.");
}
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
success = downloadFile(type.getDownloadURL() + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath);
success = downloadFile(this.type.getDownloadURL() + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath);
//TODO: Register the new version number, and only download if version mismatch or missing file.
if (!success) {
throw new FileNotFoundException("Jar file could not be downloaded.");
}
} else {
if (!file.isFile()) {
success = downloadFile(type.getDownloadURL() + this.serverVersion + type.getDownloadURLPart() + this.serverVersion + ".jar", filePath);
success = downloadFile(this.type.getDownloadURL() + this.serverVersion + type.getDownloadURLPart() + this.serverVersion + ".jar", filePath);
if (!success) {
throw new FileNotFoundException("Jar file could not be downloaded.");
}
@ -172,26 +174,28 @@ public class Server {
}
break;
case "SpongeVanilla":
type = (AdvancedServerType) this.type;
try {
versionText = readFile(this.type.getVersionURL() + this.serverVersion);
versionText = readFile(type.getVersionURL() + this.serverVersion);
} catch (IOException e) {
throw new FileNotFoundException("Version file could not be downloaded.");
}
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
success = downloadFile(type.getDownloadURL() + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath);
success = downloadFile(this.type.getDownloadURL() + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath);
//TODO: Register the new version number, and only download if version mismatch or missing file.
if (!success) {
throw new FileNotFoundException("Jar file could not be downloaded.");
}
break;
case "Bungee":
/*try {
/*type = (AdvancedServerType) this.type;
try {
versionText = readFile(this.type.getVersionURL());
} catch (IOException e) {
throw new FileNotFoundException("Version file could not be downloaded.");
}
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());*/
success = downloadFile(type.getDownloadURL(), filePath);
success = downloadFile(this.type.getDownloadURL(), filePath);
//TODO: Register the new version number, and only download if version mismatch or missing file.
if (!success) {
throw new FileNotFoundException("Jar file could not be downloaded.");