2018-01-25 17:34:45 +01:00
|
|
|
import javax.naming.ConfigurationException;
|
|
|
|
|
2018-01-25 10:53:51 +01:00
|
|
|
import net.knarcraft.serverlauncher.server.*;
|
|
|
|
|
2018-01-25 17:34:45 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
2018-01-25 10:53:51 +01:00
|
|
|
import java.util.ArrayList;
|
2018-01-25 17:34:45 +01:00
|
|
|
import java.util.Scanner;
|
2018-01-25 10:53:51 +01:00
|
|
|
|
|
|
|
public class ServerTest {
|
|
|
|
private static ArrayList<Server> servers = new ArrayList<>();
|
2018-01-25 19:55:28 +01:00
|
|
|
private static ArrayList<ServerType> serverTypes = new ArrayList<>();
|
|
|
|
|
2018-01-25 10:53:51 +01:00
|
|
|
public static void main(String[] args) {
|
2018-01-25 19:55:28 +01:00
|
|
|
try {
|
2018-01-25 17:34:45 +01:00
|
|
|
loadServerTypes();
|
|
|
|
} catch (ConfigurationException e) {
|
|
|
|
e.printStackTrace();
|
2018-01-25 19:55:28 +01:00
|
|
|
System.exit(1);
|
2018-01-25 17:34:45 +01:00
|
|
|
}
|
2018-01-25 10:53:51 +01:00
|
|
|
Server server1 = new Server("Server1");
|
|
|
|
server1.toggle();
|
|
|
|
server1.setPath("C:\\Users\\Kristian\\Desktop\\Test");
|
2018-01-25 19:55:28 +01:00
|
|
|
server1.setType(serverTypes.get(4));
|
|
|
|
//TODO: All types are inside serverTypes, but the ones of ServerType get a casting error.
|
|
|
|
server1.setServerVersion("1.12.2");
|
2018-01-25 10:53:51 +01:00
|
|
|
server1.setMaxRam("1G");
|
|
|
|
servers.add(server1);
|
2018-01-25 19:55:28 +01:00
|
|
|
startServers(servers);
|
2018-01-25 10:53:51 +01:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:55:28 +01:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
}
|
2018-01-25 10:53:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds all the valid server types and versions.
|
|
|
|
*/
|
2018-01-25 17:34:45 +01:00
|
|
|
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 {
|
2018-01-25 19:55:28 +01:00
|
|
|
throw new ConfigurationException("Error: Configuration file invalid.");
|
2018-01-25 17:34:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (FileNotFoundException e) {
|
2018-01-25 19:55:28 +01:00
|
|
|
throw new ConfigurationException("Error: Configuration file not found.");
|
2018-01-25 17:34:45 +01:00
|
|
|
} catch (ArrayIndexOutOfBoundsException e) {
|
2018-01-25 19:55:28 +01:00
|
|
|
throw new ConfigurationException("Error: Configuration file invalid.");
|
2018-01-25 10:53:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|