diff --git a/src/main/NGECore.java b/src/main/NGECore.java index 7ead765a..990371b9 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -154,6 +154,7 @@ public class NGECore { private static NGECore instance; private Config config = null; + private Config options = null; private String motd = ""; private volatile boolean isShuttingDown = false; private long galacticTime = System.currentTimeMillis(); @@ -272,12 +273,15 @@ public class NGECore { config = DefaultConfig.getConfig(); } - Config options = new Config(); + options = new Config(); options.setFilePath("options.cfg"); - boolean optionsConfigLoaded = options.loadConfigFile(); - + if (!(options.loadConfigFile())) { + System.err.println("Failed to load options.cfg!"); + options = DefaultConfig.getConfig(); + } + //if (optionsConfigLoaded && options.getInt("CLEAN.ODB.FOLDERS") > 0 || getExcludedDevelopers().contains(System.getProperty("user.name"))){ - if (optionsConfigLoaded && options.getInt("CLEAN.ODB.FOLDERS") > 0){ + if (options.getInt("CLEAN.ODB.FOLDERS") > 0){ File baseFolder = new File("./odb"); if (baseFolder.isDirectory()) { @@ -358,7 +362,7 @@ public class NGECore { reverseEngineeringService = new ReverseEngineeringService(this); petService = new PetService(this); - if (optionsConfigLoaded && options.getInt("LOAD.RESOURCE.SYSTEM") == 1) { + if (options.getInt("LOAD.RESOURCE.SYSTEM") == 1) { surveyService = new SurveyService(this); resourceService = new ResourceService(this); } @@ -434,7 +438,7 @@ public class NGECore { zoneDispatch.addService(petService); zoneDispatch.addService(invasionService); - if (optionsConfigLoaded && options.getInt("LOAD.RESOURCE.SYSTEM") == 1) { + if (options.getInt("LOAD.RESOURCE.SYSTEM") == 1) { zoneDispatch.addService(surveyService); zoneDispatch.addService(resourceService); } @@ -505,7 +509,7 @@ public class NGECore { //end terrainList - if (optionsConfigLoaded && options.getInt("LOAD.RESOURCE.SYSTEM") > 0) { + if (options.getInt("LOAD.RESOURCE.SYSTEM") > 0) { resourceService.loadResources(); } @@ -868,5 +872,9 @@ public class NGECore { // without having to change options.cfg all the time return excludedDevelopers; } + + public Config getOptions() { + return options; + } } diff --git a/src/services/CharacterService.java b/src/services/CharacterService.java index 9581945d..7488e77c 100644 --- a/src/services/CharacterService.java +++ b/src/services/CharacterService.java @@ -267,10 +267,9 @@ public class CharacterService implements INetworkDispatch { object.setHeight(clientCreateCharacter.getScale()); object.setPersistent(true); - Config options = new Config(); - options.setFilePath("options.cfg"); - boolean optionsConfigLoaded = options.loadConfigFile(); - if (optionsConfigLoaded && options.getInt("DO.ISOLATION.TESTS") > 0){ + Config options = NGECore.getInstance().getOptions(); + + if (options != null && options.getInt("DO.ISOLATION.TESTS") > 0){ object.setPosition(SpawnPoint.getRandomPosition(new Point3D(0, 0, 0), (float) 0.5, 3, core.terrainService.getPlanetByName("tatooine").getID())); } else { object.setPosition(SpawnPoint.getRandomPosition(new Point3D(3528, 0, -4804), (float) 0.5, 3, core.terrainService.getPlanetByName("tatooine").getID())); diff --git a/src/services/StaticService.java b/src/services/StaticService.java index a8d90c28..62b0ad61 100644 --- a/src/services/StaticService.java +++ b/src/services/StaticService.java @@ -59,9 +59,9 @@ public class StaticService implements INetworkDispatch { } public void spawnStatics() { - Config options = new Config(); - options.setFilePath("options.cfg"); - final boolean buildoutsDisabled = ((options.loadConfigFile() && options.getInt("LOAD.BUILDOUT_OBJECTS") == 0) ? true : false); + Config options = core.getOptions(); + + final boolean buildoutsDisabled = ((options != null && options.getInt("LOAD.BUILDOUT_OBJECTS") == 0) ? true : false); for (Planet planet : core.terrainService.getPlanetList()) { if (FileUtilities.doesFileExist("scripts/static_spawns/" + planet.getName())) { diff --git a/src/services/TerrainService.java b/src/services/TerrainService.java index 6be00dd8..9266b84a 100644 --- a/src/services/TerrainService.java +++ b/src/services/TerrainService.java @@ -208,11 +208,9 @@ public class TerrainService { if(planet.getSnapshotVisitor() != null) { Thread thread = new Thread(() -> { - Config config = new Config(); - config.setFilePath("options.cfg"); - boolean loaded = config.loadConfigFile(); - - if (loaded && config.getInt("LOAD.SNAPSHOT_OBJECTS") > 0) { + Config options = core.getOptions(); + + if (options != null && options.getInt("LOAD.SNAPSHOT_OBJECTS") > 0) { if (!core.getExcludedDevelopers().contains(System.getProperty("user.name"))){ try { core.objectService.loadSnapshotObjects(planet); @@ -222,16 +220,16 @@ public class TerrainService { } } - if (loaded && config.getInt("LOAD.BUILDOUT_OBJECTS") > 0) { + if (options != null && options.getInt("LOAD.BUILDOUT_OBJECTS") > 0) { if (!core.getExcludedDevelopers().contains(System.getProperty("user.name"))){ - if (! config.keyExists("LOAD.BUILDOUT_ONLY_FOR")){ + if (! options.keyExists("LOAD.BUILDOUT_ONLY_FOR")){ try { core.objectService.loadBuildoutObjects(planet); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } } else { - if (planet.getName().trim().equals(config.getString("LOAD.BUILDOUT_ONLY_FOR").trim())){ + if (planet.getName().trim().equals(options.getString("LOAD.BUILDOUT_ONLY_FOR").trim())){ try { core.objectService.loadBuildoutObjects(planet); } catch (InstantiationException | IllegalAccessException e) { diff --git a/src/services/gcw/InvasionService.java b/src/services/gcw/InvasionService.java index 60e7a15f..8f61c15d 100644 --- a/src/services/gcw/InvasionService.java +++ b/src/services/gcw/InvasionService.java @@ -139,11 +139,9 @@ public class InvasionService implements INetworkDispatch { public InvasionService(final NGECore core) { this.core = core; - - Config options = new Config(); - options.setFilePath("options.cfg"); - boolean optionsConfigLoaded = options.loadConfigFile(); - if (optionsConfigLoaded && options.getInt("ENABLE.INVASIONS") == 0){ + + Config options = core.getOptions(); + if (options != null && options.getInt("ENABLE.INVASIONS") == 0){ return; } diff --git a/src/services/spawn/DynamicSpawnArea.java b/src/services/spawn/DynamicSpawnArea.java index deab9250..db06d1ad 100644 --- a/src/services/spawn/DynamicSpawnArea.java +++ b/src/services/spawn/DynamicSpawnArea.java @@ -61,10 +61,9 @@ public class DynamicSpawnArea extends SpawnArea { @Handler public void onEnter(EnterEvent event) { - Config options = new Config(); - options.setFilePath("options.cfg"); - boolean optionsConfigLoaded = options.loadConfigFile(); - if (optionsConfigLoaded && options.getInt("DO.ISOLATION.TESTS") > 0){ + Config options = NGECore.getInstance().getOptions(); + + if (options != null && options.getInt("DO.ISOLATION.TESTS") > 0){ return; } diff --git a/src/services/spawn/LairSpawnArea.java b/src/services/spawn/LairSpawnArea.java index 8f123c04..b41222f1 100644 --- a/src/services/spawn/LairSpawnArea.java +++ b/src/services/spawn/LairSpawnArea.java @@ -110,10 +110,9 @@ public class LairSpawnArea extends SpawnArea { @Handler public void onEnter(EnterEvent event) { - Config options = new Config(); - options.setFilePath("options.cfg"); - boolean optionsConfigLoaded = options.loadConfigFile(); - if (optionsConfigLoaded && options.getInt("DO.ISOLATION.TESTS") > 0){ + Config options = NGECore.getInstance().getOptions(); + + if (options != null && options.getInt("DO.ISOLATION.TESTS") > 0){ return; } diff --git a/src/services/spawn/MixedSpawnArea.java b/src/services/spawn/MixedSpawnArea.java index 80691f62..8a4a5d43 100644 --- a/src/services/spawn/MixedSpawnArea.java +++ b/src/services/spawn/MixedSpawnArea.java @@ -63,10 +63,9 @@ public class MixedSpawnArea extends SpawnArea { @Handler public void onEnter(EnterEvent event) { - Config options = new Config(); - options.setFilePath("options.cfg"); - boolean optionsConfigLoaded = options.loadConfigFile(); - if (optionsConfigLoaded && options.getInt("DO.ISOLATION.TESTS") > 0){ + Config options = NGECore.getInstance().getOptions(); + + if (options != null && options.getInt("DO.ISOLATION.TESTS") > 0){ return; }