Fixes casting problems
This commit is contained in:
@ -26,35 +26,6 @@ public class Main {
|
||||
|
||||
// TODO: Add gui
|
||||
|
||||
/**
|
||||
* Adds all the valid server types and versions.
|
||||
*/
|
||||
private static void loadServerTypes() throws ConfigurationException {
|
||||
try (Scanner in = new Scanner(new File("config/servertypes.csv"))) {
|
||||
while (in.hasNextLine()) {
|
||||
String[] str = in.nextLine().split(";", -1);
|
||||
int len = str.length;
|
||||
String[] ver;
|
||||
if (str[1].contains(",")) {
|
||||
ver = str[1].split(",", -1);
|
||||
} else {
|
||||
ver = new String[]{str[1]};
|
||||
}
|
||||
if (len == 7) {
|
||||
serverTypes.add(new AdvancedServerType(str[0], ver, str[2], str[3], str[4], str[5], str[6]));
|
||||
} else if (len == 3) {
|
||||
serverTypes.add(new ServerType(str[0], ver, str[2]));
|
||||
} else {
|
||||
throw new ConfigurationException("Error: Configuration file invalid.");
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new ConfigurationException("Error: Configuration file not found.");
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new ConfigurationException("Error: Configuration file invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs all enabled servers with their settings.
|
||||
*/
|
||||
@ -83,4 +54,33 @@ public class Main {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the valid server types and versions.
|
||||
*/
|
||||
private static void loadServerTypes() throws ConfigurationException {
|
||||
try (Scanner in = new Scanner(new File("config/servertypes.csv"))) {
|
||||
while (in.hasNextLine()) {
|
||||
String[] str = in.nextLine().split(";", -1);
|
||||
int len = str.length;
|
||||
String[] ver;
|
||||
if (str[1].contains(",")) {
|
||||
ver = str[1].split(",", -1);
|
||||
} else {
|
||||
ver = new String[]{str[1]};
|
||||
}
|
||||
if (len == 7) {
|
||||
serverTypes.add(new AdvancedServerType(str[0], ver, str[2], str[3], str[4], str[5], str[6]));
|
||||
} else if (len == 3) {
|
||||
serverTypes.add(new ServerType(str[0], ver, str[2]));
|
||||
} else {
|
||||
throw new ConfigurationException("Error: Configuration file invalid.");
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new ConfigurationException("Error: Configuration file not found.");
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new ConfigurationException("Error: Configuration file invalid.");
|
||||
}
|
||||
}
|
||||
}
|
@ -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.");
|
||||
|
Reference in New Issue
Block a user