feat: made config files globally avaliable via Server

This commit is contained in:
Yannik Bretschneider 2021-06-05 23:12:06 +02:00
parent b0a37d63f8
commit 20bce266b1

View File

@ -15,10 +15,6 @@ import uulm.teamname.marvelous.server.netconnector.MarvelousServer;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
@ -31,6 +27,10 @@ import java.util.Map;
*/
public class Server {
private static PartyConfig partyConfig;
private static ScenarioConfig scenarioConfig;
private static CharacterConfig characterConfig;
public static void main(String[] args) {
ServerArgs serverArgs = new ServerArgs();
@ -66,13 +66,15 @@ public class Server {
System.exit(0);
}
Logger.info("populating static Server variables with config objects");
Server.scenarioConfig = scenarioConfig;
Server.characterConfig = characterConfig;
Server.partyConfig = partyConfig;
InetSocketAddress address = new InetSocketAddress(serverArgs.getPort());
Logger.trace("Inet address {} created", address);
var json = new JSON(characterConfig);
Logger.trace("New JSON instance created with characterConfig");
MarvelousServer netConnector = new MarvelousServer(address, json);
MarvelousServer netConnector = new MarvelousServer(address);
System.out.println("Starting server");
netConnector.start();
System.out.println("Server started");
@ -206,4 +208,19 @@ public class Server {
return config.get();
}
/** Returns the party configuration the server was initialized with */
public static PartyConfig getPartyConfig() {
return partyConfig;
}
/** Returns the scenario configuration the server was initialized with */
public static ScenarioConfig getScenarioConfig() {
return scenarioConfig;
}
/** Returns the character configuration the server was initialized with */
public static CharacterConfig getCharacterConfig() {
return characterConfig;
}
}