]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Make ConfigManager static
authorirtimaled <irtimaled@gmail.com>
Thu, 28 Dec 2017 06:10:34 +0000 (22:10 -0800)
committerirtimaled <irtimaled@gmail.com>
Sat, 30 Dec 2017 03:48:26 +0000 (19:48 -0800)
java/com/irtimaled/bbor/client/BoundingBoxOutlineReloaded.java
java/com/irtimaled/bbor/client/ClientProxy.java
java/com/irtimaled/bbor/common/CommonProxy.java
java/com/irtimaled/bbor/common/DimensionProcessor.java
java/com/irtimaled/bbor/config/ConfigManager.java
java/com/irtimaled/bbor/forge/ForgeCommonProxy.java
java/com/irtimaled/bbor/forge/ForgeMod.java

index 6361e30908a91513c215cbfd40f026c3615a9ec8..a97f7f8f534be3ca7ddf665f6f86eae4b124f31f 100644 (file)
@@ -9,11 +9,12 @@ import net.minecraft.world.chunk.Chunk;
 import java.io.File;
 
 public class BoundingBoxOutlineReloaded {
-    public static ClientProxy proxy;
+    private static ClientProxy proxy;
 
     public static void init() {
+        ConfigManager.loadConfig(new File(Minecraft.getMinecraft().mcDataDir, "config"));
         proxy = new ClientProxy();
-        proxy.init(new ConfigManager(new File(Minecraft.getMinecraft().mcDataDir, "config")));
+        proxy.init();
     }
 
     public static void chunkLoaded(Chunk chunk) {
index 1c23c8c9cda6979c4ed13995cdafe3908aeb43db..970bbd988299d377de291b4dc86d10e3583bccbb 100644 (file)
@@ -61,8 +61,8 @@ public class ClientProxy extends CommonProxy {
     }
 
     @Override
-    public void init(ConfigManager configManager) {
-        super.init(configManager);
+    public void init() {
+        super.init();
         String category = "Bounding Box Outline Reloaded";
         activeHotKey = new KeyBinding("Toggle On/Off", Keyboard.KEY_B, category);
         outerBoxOnlyHotKey = new KeyBinding("Toggle Display Outer Box Only", Keyboard.KEY_O, category);
@@ -104,16 +104,16 @@ public class ClientProxy extends CommonProxy {
     private void loadLocalStructures(String host, int port) {
         Logger.info("Looking for local structures (host:port=%s:%d)", host, port);
         String path = String.format("BBOutlineReloaded%s%s%s%d", File.separator, host, File.separator, port);
-        File localStructuresFolder = new File(configManager.configDir, path);
+        File localStructuresFolder = new File(ConfigManager.configDir, path);
         Logger.info("Looking for local structures (folder=%s)", localStructuresFolder.getAbsolutePath());
         if (!localStructuresFolder.exists()) {
             path = String.format("BBOutlineReloaded%s%s", File.separator, host);
-            localStructuresFolder = new File(configManager.configDir, path);
+            localStructuresFolder = new File(ConfigManager.configDir, path);
             Logger.info("Looking for local structures (folder=%s)", localStructuresFolder.getAbsolutePath());
         }
         if (!localStructuresFolder.exists()) {
             path = String.format("BBOutlineReloaded%s%s,%d", File.separator, host, port);
-            localStructuresFolder = new File(configManager.configDir, path);
+            localStructuresFolder = new File(ConfigManager.configDir, path);
             Logger.info("Looking for local structures (folder=%s)", localStructuresFolder.getAbsolutePath());
         }
         if (!localStructuresFolder.exists()) {
@@ -128,28 +128,28 @@ public class ClientProxy extends CommonProxy {
 
     private void loadOverworldStructures(File localStructuresFolder) {
         BoundingBoxCache cache = new BoundingBoxCache();
-        if (configManager.drawDesertTemples.getBoolean()) {
+        if (ConfigManager.drawDesertTemples.getBoolean()) {
             loadStructureNbtFile(localStructuresFolder, cache, "Temple.dat", StructureType.DesertTemple.getColor(), "TeDP");
         }
-        if (configManager.drawJungleTemples.getBoolean()) {
+        if (ConfigManager.drawJungleTemples.getBoolean()) {
             loadStructureNbtFile(localStructuresFolder, cache, "Temple.dat", StructureType.JungleTemple.getColor(), "TeJP");
         }
-        if (configManager.drawWitchHuts.getBoolean()) {
+        if (ConfigManager.drawWitchHuts.getBoolean()) {
             loadStructureNbtFile(localStructuresFolder, cache, "Temple.dat", StructureType.WitchHut.getColor(), "TeSH");
         }
-        if (configManager.drawOceanMonuments.getBoolean()) {
+        if (ConfigManager.drawOceanMonuments.getBoolean()) {
             loadStructureNbtFile(localStructuresFolder, cache, "Monument.dat", StructureType.OceanMonument.getColor(), "*");
         }
-        if (configManager.drawStrongholds.getBoolean()) {
+        if (ConfigManager.drawStrongholds.getBoolean()) {
             loadStructureNbtFile(localStructuresFolder, cache, "Stronghold.dat", StructureType.Stronghold.getColor(), "*");
         }
-        if (configManager.drawMansions.getBoolean()) {
+        if (ConfigManager.drawMansions.getBoolean()) {
             loadStructureNbtFile(localStructuresFolder, cache, "Mansion.dat", StructureType.Mansion.getColor(), "*");
         }
-        if (configManager.drawMineShafts.getBoolean()) {
+        if (ConfigManager.drawMineShafts.getBoolean()) {
             loadStructureNbtFile(localStructuresFolder, cache, "Mineshaft.dat", StructureType.MineShaft.getColor(), "*");
         }
-        if (configManager.drawVillages.getBoolean()) {
+        if (ConfigManager.drawVillages.getBoolean()) {
             loadVillageNbtFile(localStructuresFolder, cache, "Villages.dat");
         }
 
@@ -158,9 +158,9 @@ public class ClientProxy extends CommonProxy {
 
     private void loadNetherStructures(File localStructuresFolder) {
         BoundingBoxCache cache = new BoundingBoxCache();
-        if (configManager.drawNetherFortresses.getBoolean())
+        if (ConfigManager.drawNetherFortresses.getBoolean())
             loadStructureNbtFile(localStructuresFolder, cache, "Fortress.dat", StructureType.NetherFortress.getColor(), "*");
-        if (configManager.drawVillages.getBoolean()) {
+        if (ConfigManager.drawVillages.getBoolean()) {
             loadVillageNbtFile(localStructuresFolder, cache, "villages_nether.dat");
         }
         boundingBoxCacheMap.put(DimensionType.NETHER, cache);
@@ -168,10 +168,10 @@ public class ClientProxy extends CommonProxy {
 
     private void loadEndStructures(File localStructuresFolder) {
         BoundingBoxCache cache = new BoundingBoxCache();
-        if (configManager.drawVillages.getBoolean()) {
+        if (ConfigManager.drawVillages.getBoolean()) {
             loadVillageNbtFile(localStructuresFolder, cache, "Villages_end.dat");
         }
-        if (configManager.drawEndCities.getBoolean()) {
+        if (ConfigManager.drawEndCities.getBoolean()) {
             loadStructureNbtFile(localStructuresFolder, cache, "EndCity.dat", StructureType.EndCity.getColor(), "*");
         }
         boundingBoxCacheMap.put(DimensionType.THE_END, cache);
@@ -265,7 +265,7 @@ public class ClientProxy extends CommonProxy {
 
     public void playerDisconnectedFromServer() {
         active = false;
-        if (configManager.keepCacheBetweenSessions.getBoolean()) return;
+        if (ConfigManager.keepCacheBetweenSessions.getBoolean()) return;
         worldData = null;
         worldSpawnBoundingBox = null;
         spawnChunksBoundingBox = null;
@@ -284,7 +284,7 @@ public class ClientProxy extends CommonProxy {
         GL11.glDisable(GL11.GL_TEXTURE_2D);
         GL11.glDisable(GL11.GL_CULL_FACE);
 
-        if (configManager.alwaysVisible.getBoolean()) {
+        if (ConfigManager.alwaysVisible.getBoolean()) {
             GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
         }
 
@@ -320,16 +320,16 @@ public class ClientProxy extends CommonProxy {
 
         if (bb instanceof BoundingBoxVillage) {
             BoundingBoxVillage villageBB = (BoundingBoxVillage) bb;
-            if (configManager.renderVillageAsSphere.getBoolean()) {
+            if (ConfigManager.renderVillageAsSphere.getBoolean()) {
                 renderBoundingBoxVillageAsSphere(villageBB);
             } else {
                 renderBoundingBox(villageBB);
             }
-            if (configManager.drawIronGolemSpawnArea.getBoolean() &&
+            if (ConfigManager.drawIronGolemSpawnArea.getBoolean() &&
                     villageBB.getSpawnsIronGolems()) {
                 renderIronGolemSpawnArea(villageBB);
             }
-            if (configManager.drawVillageDoors.getBoolean())
+            if (ConfigManager.drawVillageDoors.getBoolean())
                 renderVillageDoors(villageBB);
         } else if (bb instanceof BoundingBoxSlimeChunk) {
             renderSlimeChunk((BoundingBoxSlimeChunk) bb);
@@ -349,7 +349,7 @@ public class ClientProxy extends CommonProxy {
     private void renderWorldSpawn(BoundingBoxWorldSpawn bb) {
         AxisAlignedBB aaBB = bb.toAxisAlignedBB(false);
         Color color = bb.getColor();
-        double y = getMaxY(configManager.worldSpawnMaxY.getInt()) + 0.001F;
+        double y = getMaxY(ConfigManager.worldSpawnMaxY.getInt()) + 0.001F;
         renderRectangle(aaBB, y, y, color, false);
     }
 
@@ -358,7 +358,7 @@ public class ClientProxy extends CommonProxy {
         Color color = bb.getColor();
         renderCuboid(aaBB, color, fill());
 
-        double maxY = getMaxY(configManager.slimeChunkMaxY.getInt());
+        double maxY = getMaxY(ConfigManager.slimeChunkMaxY.getInt());
         if (maxY > 39) {
             renderRectangle(aaBB, 39, maxY, color, fill());
         }
@@ -379,7 +379,7 @@ public class ClientProxy extends CommonProxy {
     }
 
     private boolean fill() {
-        return configManager.fill.getBoolean();
+        return ConfigManager.fill.getBoolean();
     }
 
     private void renderIronGolemSpawnArea(BoundingBoxVillage villageBB) {
@@ -623,14 +623,14 @@ public class ClientProxy extends CommonProxy {
         }
 
         Set<BoundingBox> boundingBoxes = new HashSet<>();
-        if (configManager.drawWorldSpawn.getBoolean()) {
+        if (ConfigManager.drawWorldSpawn.getBoolean()) {
             boundingBoxes.add(getWorldSpawnBoundingBox(worldData.getSpawnX(), worldData.getSpawnZ()));
             boundingBoxes.add(getSpawnChunksBoundingBox(worldData.getSpawnX(), worldData.getSpawnZ()));
         }
-        if (configManager.drawLazySpawnChunks.getBoolean()) {
+        if (ConfigManager.drawLazySpawnChunks.getBoolean()) {
             boundingBoxes.add(getLazySpawnChunksBoundingBox(worldData.getSpawnX(), worldData.getSpawnZ()));
         }
-        if (configManager.drawSlimeChunks.getBoolean()) {
+        if (ConfigManager.drawSlimeChunks.getBoolean()) {
             boundingBoxes.addAll(this.getSlimeChunks());
         }
         return boundingBoxes;
index f53e990cd724bfb04b735d3ea050963e841e1ea8..e6284d0006c76d83768818da397755942e6836b2 100644 (file)
@@ -17,12 +17,10 @@ import java.util.concurrent.ConcurrentHashMap;
 public class CommonProxy {
     public Map<DimensionType, BoundingBoxCache> boundingBoxCacheMap = new ConcurrentHashMap<>();
 
-    public ConfigManager configManager;
     protected WorldData worldData;
     private IEventHandler eventHandler = null;
 
-    public void init(ConfigManager configManager) {
-        this.configManager = configManager;
+    public void init() {
     }
 
     public void worldLoaded(World world) {
@@ -32,7 +30,7 @@ public class CommonProxy {
             setWorldData(new WorldData(world.getSeed(), world.getWorldInfo().getSpawnX(), world.getWorldInfo().getSpawnZ()));
             DimensionType dimensionType = world.provider.getDimensionType();
             Logger.info("create world dimension: %s, %s (chunkprovider: %s) (seed: %d)", dimensionType, world.getClass().toString(), chunkGenerator.getClass().toString(), worldData.getSeed());
-            boundingBoxCacheMap.put(dimensionType, new DimensionProcessor(eventHandler, configManager, world, dimensionType, chunkGenerator));
+            boundingBoxCacheMap.put(dimensionType, new DimensionProcessor(eventHandler, world, dimensionType, chunkGenerator));
         }
     }
 
index a0d1ccfcd0032ba49bbcd7a85433ecfd629b057b..16c8a230cfdd96dccb3f815609e374a61c603152 100644 (file)
@@ -23,13 +23,11 @@ import java.util.*;
 import java.util.List;
 
 public class DimensionProcessor extends BoundingBoxCache {
-    private ConfigManager configManager;
     private World world;
     private IEventHandler eventHandler;
 
-    public DimensionProcessor(IEventHandler eventHandler, ConfigManager configManager, World world, DimensionType dimensionType, IChunkGenerator chunkGenerator) {
+    public DimensionProcessor(IEventHandler eventHandler, World world, DimensionType dimensionType, IChunkGenerator chunkGenerator) {
         this.eventHandler = eventHandler;
-        this.configManager = configManager;
         this.world = world;
         this.dimensionType = dimensionType;
         this.chunkGenerator = chunkGenerator;
@@ -69,39 +67,39 @@ public class DimensionProcessor extends BoundingBoxCache {
     private Map<StructureType, Collection<StructureStart>> getStructures() {
         Map<StructureType, Collection<StructureStart>> structureMap = new HashMap<>();
         if (chunkGenerator instanceof ChunkGeneratorOverworld) {
-            if (configManager.drawDesertTemples.getBoolean()) {
+            if (ConfigManager.drawDesertTemples.getBoolean()) {
                 structureMap.put(StructureType.DesertTemple, getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.DesertPyramid.class));
             }
 
-            if (configManager.drawJungleTemples.getBoolean()) {
+            if (ConfigManager.drawJungleTemples.getBoolean()) {
                 structureMap.put(StructureType.JungleTemple, getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.JunglePyramid.class));
             }
 
-            if (configManager.drawWitchHuts.getBoolean()) {
+            if (ConfigManager.drawWitchHuts.getBoolean()) {
                 structureMap.put(StructureType.WitchHut, getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.SwampHut.class));
             }
 
-            if (configManager.drawOceanMonuments.getBoolean()) {
+            if (ConfigManager.drawOceanMonuments.getBoolean()) {
                 structureMap.put(StructureType.OceanMonument, getStructures(chunkGenerator, StructureOceanMonument.class));
             }
 
-            if (configManager.drawStrongholds.getBoolean()) {
+            if (ConfigManager.drawStrongholds.getBoolean()) {
                 structureMap.put(StructureType.Stronghold, getStructures(chunkGenerator, MapGenStronghold.class));
             }
 
-            if (configManager.drawMansions.getBoolean()) {
+            if (ConfigManager.drawMansions.getBoolean()) {
                 structureMap.put(StructureType.Mansion, getStructures(chunkGenerator, WoodlandMansion.class));
             }
 
-            if (configManager.drawMineShafts.getBoolean()) {
+            if (ConfigManager.drawMineShafts.getBoolean()) {
                 structureMap.put(StructureType.MineShaft, getStructures(chunkGenerator, MapGenMineshaft.class));
             }
         } else if (chunkGenerator instanceof ChunkGeneratorHell) {
-            if (configManager.drawNetherFortresses.getBoolean()) {
+            if (ConfigManager.drawNetherFortresses.getBoolean()) {
                 structureMap.put(StructureType.NetherFortress, getStructures(chunkGenerator, MapGenNetherBridge.class));
             }
         } else if (chunkGenerator instanceof ChunkGeneratorEnd) {
-            if (configManager.drawEndCities.getBoolean()) {
+            if (ConfigManager.drawEndCities.getBoolean()) {
                 structureMap.put(StructureType.EndCity, getStructures(chunkGenerator, MapGenEndCity.class));
             }
         }
@@ -141,7 +139,7 @@ public class DimensionProcessor extends BoundingBoxCache {
             }
         }
 
-        if (configManager.drawVillages.getBoolean() &&
+        if (ConfigManager.drawVillages.getBoolean() &&
                 world.getVillageCollection() != null) {
             Map<Integer, BoundingBoxVillage> villageBoundingBoxes = new HashMap<>();
             List<Village> villages = world.getVillageCollection().getVillageList();
index 80936f72559f18d76d0cc2996359a318b72fa480..1551461a58cfa41a61ccb7497130a95598ed63cc 100644 (file)
@@ -3,34 +3,34 @@ package com.irtimaled.bbor.config;
 import java.io.File;
 
 public class ConfigManager {
-    public final File configDir;
+    public static File configDir;
 
-    public Setting fill;
-    public Setting drawVillages;
-    public Setting drawDesertTemples;
-    public Setting drawJungleTemples;
-    public Setting drawWitchHuts;
-    public Setting drawStrongholds;
-    public Setting drawMineShafts;
-    public Setting drawNetherFortresses;
-    public Setting drawOceanMonuments;
-    public Setting alwaysVisible;
-    public Setting renderVillageAsSphere;
-    public Setting drawIronGolemSpawnArea;
-    public Setting drawVillageDoors;
-    public Setting drawSlimeChunks;
-    public Setting slimeChunkMaxY;
-    public Setting keepCacheBetweenSessions;
-    public Setting drawWorldSpawn;
-    public Setting worldSpawnMaxY;
-    public Setting drawLazySpawnChunks;
-    public Setting drawEndCities;
-    public Setting drawMansions;
+    public static Setting fill;
+    public static Setting drawVillages;
+    public static Setting drawDesertTemples;
+    public static Setting drawJungleTemples;
+    public static Setting drawWitchHuts;
+    public static Setting drawStrongholds;
+    public static Setting drawMineShafts;
+    public static Setting drawNetherFortresses;
+    public static Setting drawOceanMonuments;
+    public static Setting alwaysVisible;
+    public static Setting renderVillageAsSphere;
+    public static Setting drawIronGolemSpawnArea;
+    public static Setting drawVillageDoors;
+    public static Setting drawSlimeChunks;
+    public static Setting slimeChunkMaxY;
+    public static Setting keepCacheBetweenSessions;
+    public static Setting drawWorldSpawn;
+    public static Setting worldSpawnMaxY;
+    public static Setting drawLazySpawnChunks;
+    public static Setting drawEndCities;
+    public static Setting drawMansions;
 
-    private Configuration config;
+    private static Configuration config;
 
-    public ConfigManager(File configDir) {
-        this.configDir = configDir;
+    public static void loadConfig(File mcConfigDir) {
+        configDir = mcConfigDir;
         config = new Configuration(new File(configDir, "BBOutlineReloaded.cfg"));
         config.load();
 
@@ -58,14 +58,14 @@ public class ConfigManager {
         config.save();
     }
 
-    private Setting SetupBooleanProperty(Configuration config, String category, String settingName, Boolean defaultValue, String comment) {
+    private static Setting SetupBooleanProperty(Configuration config, String category, String settingName, Boolean defaultValue, String comment) {
         Setting property = config.get(category, settingName, defaultValue);
         property.comment = comment;
         property.set(property.getBoolean(defaultValue));
         return property;
     }
 
-    private Setting SetupIntegerProperty(Configuration config, String category, String settingName, int defaultValue, String comment) {
+    private static Setting SetupIntegerProperty(Configuration config, String category, String settingName, int defaultValue, String comment) {
         Setting property = config.get(category, settingName, defaultValue);
         property.comment = comment;
         property.set(property.getInt(defaultValue));
index 1d2099759ecf093bcadd42c1d314ed0935b61617..c5e630d086919ac4d56b9e022b3f61537e31795c 100644 (file)
@@ -53,10 +53,10 @@ public class ForgeCommonProxy implements IEventHandler {
     protected SimpleNetworkWrapper network;
     private CommonProxy commonProxy;
 
-    public void init(ConfigManager configManager) {
+    public void init() {
         CommonProxy proxy = getProxy();
         proxy.setEventHandler(this);
-        proxy.init(configManager);
+        proxy.init();
         network = NetworkRegistry.INSTANCE.newSimpleChannel("bbor");
         network.registerMessage(AddBoundingBoxMessageHandler.class, AddBoundingBoxMessage.class, 0, Side.CLIENT);
         network.registerMessage(RemoveBoundingBoxMessageHandler.class, RemoveBoundingBoxMessage.class, 1, Side.CLIENT);
index 955312b463f5d63c7ecb50b43b59ef9b0cc437de..b702e52ac39cde5c63194d3ce750e2f4c570f794 100644 (file)
@@ -15,8 +15,6 @@ public class ForgeMod {
     public static final String VERSION = "1.0.0-beta18";
     public static final String MCVERSION = "1.12";
 
-    private ConfigManager configManager;
-
     public SimpleNetworkWrapper network;
 
     @Mod.Instance()
@@ -27,12 +25,12 @@ public class ForgeMod {
 
     @Mod.EventHandler
     public void preInit(FMLPreInitializationEvent evt) {
-        configManager = new ConfigManager(evt.getModConfigurationDirectory());
+        ConfigManager.loadConfig(evt.getModConfigurationDirectory());
     }
 
     @Mod.EventHandler
     public void load(FMLInitializationEvent evt) {
         MinecraftForge.EVENT_BUS.register(proxy);
-        proxy.init(configManager);
+        proxy.init();
     }
 }