This commit is contained in:
2018-01-25 21:17:02 +01:00
parent 7843331605
commit fdb02a6428
5 changed files with 117 additions and 135 deletions

View File

@ -1,70 +1,35 @@
import javax.naming.ConfigurationException;
import net.knarcraft.serverlauncher.server.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
/**
* A class for testing new and existing features.
*
* @author Kristian Knarvik <kristian.knarvik@knett.no>
* @version 0.0.0.1
* @since 0.0.0.1
*/
public class ServerTest {
private static ArrayList<Server> servers = new ArrayList<>();
private static ArrayList<ServerType> serverTypes = new ArrayList<>();
public static void main(String[] args) {
try {
loadServerTypes();
ServerType.loadServerTypes();
} catch (ConfigurationException e) {
e.printStackTrace();
System.exit(1);
}
Server server1 = new Server("Server1");
new Server("Server1");
Server server1 = Server.getServers().get(0);
server1.toggle();
server1.setPath("C:\\Users\\Kristian\\Desktop\\Test");
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");
server1.setType(ServerType.getServerTypes().get(6));
server1.setServerVersion("1.6.4");
server1.setMaxRam("1G");
servers.add(server1);
startServers(servers);
Server.startServers();
}
/**
* 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.
*/
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.");
}
}
}