Fixes casting problems
This commit is contained in:
parent
5e4b956e19
commit
7843331605
@ -26,35 +26,6 @@ public class Main {
|
|||||||
|
|
||||||
// TODO: Add gui
|
// 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.
|
* 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 String path;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private ArrayList<String> playerList;
|
private ArrayList<String> playerList;
|
||||||
private AdvancedServerType type;
|
private ServerType type;
|
||||||
private String serverVersion;
|
private String serverVersion;
|
||||||
private String maxRam;
|
private String maxRam;
|
||||||
private long pid;
|
private long pid;
|
||||||
@ -71,7 +71,7 @@ public class Server {
|
|||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(AdvancedServerType type) {
|
public void setType(ServerType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,6 +127,7 @@ public class Server {
|
|||||||
* @throws FileNotFoundException if the file was not found and could not be acquired.
|
* @throws FileNotFoundException if the file was not found and could not be acquired.
|
||||||
*/
|
*/
|
||||||
public void downloadJar() throws FileNotFoundException {
|
public void downloadJar() throws FileNotFoundException {
|
||||||
|
AdvancedServerType type;
|
||||||
File file = new File(this.path + "\\" + this.getType());
|
File file = new File(this.path + "\\" + this.getType());
|
||||||
Path filePath = Paths.get(this.path + "\\" + this.getType());
|
Path filePath = Paths.get(this.path + "\\" + this.getType());
|
||||||
String versionText;
|
String versionText;
|
||||||
@ -142,7 +143,7 @@ public class Server {
|
|||||||
case "Craftbukkit":
|
case "Craftbukkit":
|
||||||
case "MCPCplus":
|
case "MCPCplus":
|
||||||
if (!file.isFile()) {
|
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) {
|
if (!success) {
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
}
|
}
|
||||||
@ -150,21 +151,22 @@ public class Server {
|
|||||||
break;
|
break;
|
||||||
case "Vanilla":
|
case "Vanilla":
|
||||||
case "Snapshot":
|
case "Snapshot":
|
||||||
|
type = (AdvancedServerType) this.type;
|
||||||
if (this.serverVersion.equals("Latest")) {
|
if (this.serverVersion.equals("Latest")) {
|
||||||
try {
|
try {
|
||||||
versionText = readFile(this.type.getVersionURL());
|
versionText = readFile(type.getVersionURL());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileNotFoundException("Version file could not be downloaded.");
|
throw new FileNotFoundException("Version file could not be downloaded.");
|
||||||
}
|
}
|
||||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
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.
|
//TODO: Register the new version number, and only download if version mismatch or missing file.
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!file.isFile()) {
|
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) {
|
if (!success) {
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
}
|
}
|
||||||
@ -172,26 +174,28 @@ public class Server {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "SpongeVanilla":
|
case "SpongeVanilla":
|
||||||
|
type = (AdvancedServerType) this.type;
|
||||||
try {
|
try {
|
||||||
versionText = readFile(this.type.getVersionURL() + this.serverVersion);
|
versionText = readFile(type.getVersionURL() + this.serverVersion);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileNotFoundException("Version file could not be downloaded.");
|
throw new FileNotFoundException("Version file could not be downloaded.");
|
||||||
}
|
}
|
||||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
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.
|
//TODO: Register the new version number, and only download if version mismatch or missing file.
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Bungee":
|
case "Bungee":
|
||||||
/*try {
|
/*type = (AdvancedServerType) this.type;
|
||||||
|
try {
|
||||||
versionText = readFile(this.type.getVersionURL());
|
versionText = readFile(this.type.getVersionURL());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileNotFoundException("Version file could not be downloaded.");
|
throw new FileNotFoundException("Version file could not be downloaded.");
|
||||||
}
|
}
|
||||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());*/
|
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.
|
//TODO: Register the new version number, and only download if version mismatch or missing file.
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
import javax.crypto.Cipher;
|
|
||||||
import javax.crypto.KeyGenerator;
|
|
||||||
import javax.crypto.SecretKey;
|
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
import net.knarcraft.serverlauncher.server.*;
|
import net.knarcraft.serverlauncher.server.*;
|
||||||
@ -11,25 +8,36 @@ import java.util.ArrayList;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class ServerTest {
|
public class ServerTest {
|
||||||
private static ArrayList<ServerType> serverTypes = new ArrayList<>();
|
|
||||||
private static ArrayList<Server> servers = new ArrayList<>();
|
private static ArrayList<Server> servers = new ArrayList<>();
|
||||||
|
private static ArrayList<ServerType> serverTypes = new ArrayList<>();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
/*try {
|
try {
|
||||||
loadServerTypes();
|
loadServerTypes();
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
System.exit(1);
|
||||||
}
|
}
|
||||||
Server server1 = new Server("Server1");
|
Server server1 = new Server("Server1");
|
||||||
server1.toggle();
|
server1.toggle();
|
||||||
server1.setPath("C:\\Users\\Kristian\\Desktop\\Test");
|
server1.setPath("C:\\Users\\Kristian\\Desktop\\Test");
|
||||||
server1.setType((AdvancedServerType) serverTypes.get(2));
|
server1.setType(serverTypes.get(4));
|
||||||
server1.setServerVersion("1.10.2");
|
//TODO: All types are inside serverTypes, but the ones of ServerType get a casting error.
|
||||||
|
server1.setServerVersion("1.12.2");
|
||||||
server1.setMaxRam("1G");
|
server1.setMaxRam("1G");
|
||||||
servers.add(server1);
|
servers.add(server1);
|
||||||
startServers(servers);*/
|
startServers(servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs all enabled servers with their settings.
|
||||||
|
*/
|
||||||
|
private static void startServers(ArrayList<Server> servers) {
|
||||||
|
System.out.println("Starting servers.");
|
||||||
|
for (Server server : servers) {
|
||||||
|
server.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds all the valid server types and versions.
|
* Adds all the valid server types and versions.
|
||||||
@ -50,23 +58,13 @@ public class ServerTest {
|
|||||||
} else if (len == 3) {
|
} else if (len == 3) {
|
||||||
serverTypes.add(new ServerType(str[0], ver, str[2]));
|
serverTypes.add(new ServerType(str[0], ver, str[2]));
|
||||||
} else {
|
} else {
|
||||||
throw new ConfigurationException("Error: Config file invalid.");
|
throw new ConfigurationException("Error: Configuration file invalid.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new ConfigurationException("Error: Config file not found.");
|
throw new ConfigurationException("Error: Configuration file not found.");
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
throw new ConfigurationException("Error: Config file invalid.");
|
throw new ConfigurationException("Error: Configuration file invalid.");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs all enabled servers with their settings.
|
|
||||||
*/
|
|
||||||
public static void startServers(ArrayList<Server> servers) {
|
|
||||||
System.out.println("Starting servers.");
|
|
||||||
for (Server server : servers) {
|
|
||||||
server.run();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user