]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/config/ConfigManager.java
Add config command to allow easier config editing
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / config / ConfigManager.java
1 package com.irtimaled.bbor.config;
2
3 import java.io.File;
4 import java.util.HashSet;
5 import java.util.Set;
6
7 public class ConfigManager {
8     private static final Set<Setting<?>> settings = new HashSet<>();
9     public static File configDir;
10
11     public static Setting<Boolean> fill;
12     public static Setting<Boolean> drawVillages;
13     public static Setting<Boolean> drawDesertTemples;
14     public static Setting<Boolean> drawJungleTemples;
15     public static Setting<Boolean> drawWitchHuts;
16     public static Setting<Boolean> drawStrongholds;
17     public static Setting<Boolean> drawMineShafts;
18     public static Setting<Boolean> drawNetherFortresses;
19     public static Setting<Boolean> drawOceanMonuments;
20     public static Setting<Boolean> alwaysVisible;
21     public static Setting<Boolean> drawIronGolemSpawnArea;
22     public static Setting<Boolean> drawVillageDoors;
23     public static Setting<Boolean> drawSlimeChunks;
24     public static Setting<Integer> slimeChunkMaxY;
25     public static Setting<Boolean> keepCacheBetweenSessions;
26     public static Setting<Boolean> drawWorldSpawn;
27     public static Setting<Integer> worldSpawnMaxY;
28     public static Setting<Boolean> drawLazySpawnChunks;
29     public static Setting<Boolean> drawEndCities;
30     public static Setting<Boolean> drawMansions;
31     public static Setting<Boolean> drawShipwrecks;
32     public static Setting<Boolean> drawOceanRuins;
33     public static Setting<Boolean> drawBuriedTreasure;
34     public static Setting<Boolean> drawIgloos;
35     public static Setting<Boolean> drawMobSpawners;
36     public static Setting<Boolean> renderMobSpawnerSpawnArea;
37     public static Setting<Boolean> renderMobSpawnerActivationLines;
38     public static Setting<Boolean> drawPillagerOutposts;
39     public static Setting<Boolean> outerBoxesOnly;
40     public static Setting<Integer> villageSphereDotSize;
41     public static Setting<Integer> villageSphereDensity;
42     public static Setting<Boolean> drawVillageSpheres;
43     public static Setting<Boolean> drawAFKSpheres;
44     public static Setting<Boolean> renderAFKSpawnableBlocks;
45     public static Setting<Integer> afkSpawnableBlocksRenderDistance;
46     public static Setting<Boolean> drawBeacons;
47     public static Setting<Boolean> drawCustomBoxes;
48     public static Setting<Boolean> drawBiomeBorders;
49     public static Setting<Boolean> renderOnlyCurrentBiome;
50     public static Setting<Integer> biomeBordersRenderDistance;
51     public static Setting<Integer> biomeBordersMaxY;
52     public static Setting<Boolean> drawNetherFossils;
53     public static Setting<Boolean> drawBastionRemnants;
54     public static Setting<Boolean> drawRuinedPortals;
55
56     public static void loadConfig(File mcConfigDir) {
57         configDir = new File(mcConfigDir, "config");
58         configDir.mkdirs();
59         Configuration config = loadConfig();
60
61         fill = setup(config, "general", "fill", true, "If set to true the bounding boxes are filled.");
62         outerBoxesOnly = setup(config, "general", "outerBoxesOnly", false, "If set to true only the outer bounding boxes are rendered.");
63         alwaysVisible = setup(config, "general", "alwaysVisible", false, "If set to true boxes will be visible even through other blocks.");
64         keepCacheBetweenSessions = setup(config, "general", "keepCacheBetweenSessions", false, "If set to true bounding box caches will be kept between sessions.");
65         drawBeacons = setup(config, "general", "drawBeacons", true, "If set to true beacon bounding boxes will be drawn.");
66         drawCustomBoxes = setup(config, "general", "drawCustomBoxes", true, "If set to true custom bounding boxes will be drawn.");
67         drawBiomeBorders = setup(config, "biomeBorders", "drawBiomeBorders", true, "If set to true biome borders will be drawn.");
68         renderOnlyCurrentBiome = setup(config, "biomeBorders", "renderOnlyCurrentBiome", true, "If set to true only the biome border for the current biome will be drawn.");
69         biomeBordersRenderDistance = setup(config, "biomeBorders", "biomeBordersRenderDistance", 3, "The distance from the player where biome borders will be drawn.");
70         biomeBordersMaxY = setup(config, "biomeBorders", "biomeBordersMaxY", -1, "The maximum top of the biome borders. If set to -1 it will use the value when activated, if set to 0 it will always track the players feet.");
71
72         drawVillageSpheres = setup(config, "villages", "drawVillageSpheres", true, "If set to true village bounding spheres are drawn.");
73         drawIronGolemSpawnArea = setup(config, "villages", "drawIronGolemSpawnArea", true, "If set to true the iron golem spawn area of the village will be drawn. (default:true)");
74         drawVillageDoors = setup(config, "villages", "drawVillageDoors", false, "If set to true lines between the village centre and doors will be drawn. (default:false)");
75         villageSphereDotSize = setup(config, "villages", "villageSphereDotSize", 2, "The size of the dots used when rendering village as sphere.");
76         villageSphereDensity = setup(config, "villages", "villageSphereDensity", 3, "The density of the dots used when rendering village as sphere.");
77
78         drawVillages = setup(config, "structures", "drawVillages", false, "If set to true village bounding boxes will be drawn.");
79         drawDesertTemples = setup(config, "structures", "drawDesertTemples", true, "If set to true desert temple bounding boxes are drawn.");
80         drawJungleTemples = setup(config, "structures", "drawJungleTemples", true, "If set to true jungle temple bounding boxes are drawn.");
81         drawWitchHuts = setup(config, "structures", "drawWitchHuts", true, "If set to true witch hut bounding boxes are drawn.");
82         drawStrongholds = setup(config, "structures", "drawStrongholds", false, "If set to true stronghold bounding boxes are drawn.");
83         drawMineShafts = setup(config, "structures", "drawMineShafts", false, "If set to true mineshaft bounding boxes are drawn.");
84         drawNetherFortresses = setup(config, "structures", "drawNetherFortresses", true, "If set to true nether fortress bounding boxes are drawn.");
85         drawOceanMonuments = setup(config, "structures", "drawOceanMonuments", true, "If set to true ocean monument bounding boxes are drawn.");
86         drawEndCities = setup(config, "structures", "drawEndCities", true, "If set to true end city bounding boxes will be drawn.");
87         drawMansions = setup(config, "structures", "drawMansions", true, "If set to true woodland mansions will be drawn.");
88         drawIgloos = setup(config, "structures", "drawIgloos", true, "If set to true igloos will be drawn.");
89         drawShipwrecks = setup(config, "structures", "drawShipwrecks", true, "If set to true shipwrecks will be drawn.");
90         drawOceanRuins = setup(config, "structures", "drawOceanRuins", true, "If set to true ocean ruins will be drawn.");
91         drawBuriedTreasure = setup(config, "structures", "drawBuriedTreasures", true, "If set to true buried treasure will be drawn.");
92         drawPillagerOutposts = setup(config, "structures", "drawPillagerOutposts", true, "If set to true pillager outposts will be drawn.");
93         drawNetherFossils = setup(config, "structures", "drawNetherFossils", true, "If set to true nether fossils will be drawn.");
94         drawBastionRemnants = setup(config, "structures", "drawBastionRemnants", true, "If set to true bastion remnants will be drawn.");
95         drawRuinedPortals = setup(config, "structures", "drawRuinedPortals", true, "If set to true ruined portals will be drawn.");
96
97         drawSlimeChunks = setup(config, "slimeChunks", "drawSlimeChunks", true, "If set to true slime chunks bounding boxes are drawn.");
98         slimeChunkMaxY = setup(config, "slimeChunks", "slimeChunkMaxY", -1, "The maximum top of the slime chunk bounding box. If set to -1 it will use the value when activated, if set to 0 it will always track the player's feet.");
99
100         drawWorldSpawn = setup(config, "worldSpawn", "drawWorldSpawn", true, "If set to true world spawn and spawn chunks bounding boxes are drawn.");
101         worldSpawnMaxY = setup(config, "worldSpawn", "worldSpawnMaxY", -1, "The maximum top of the world spawn bounding boxes. If set to -1 it will use the value when activated, if set to 0 it will always track the players feet.");
102         drawLazySpawnChunks = setup(config, "worldSpawn", "drawLazySpawnChunks", false, "If set to true the lazy spawn chunks bounding boxes will be drawn.");
103
104         drawMobSpawners = setup(config, "mobSpawners", "drawMobSpawners", true, "If set to true mob spawners will be drawn.");
105         renderMobSpawnerSpawnArea = setup(config, "mobSpawners", "renderMobSpawnerSpawnArea", true, "If set to true a box to show the maximum possible spawn area (10x10x4) for a spawner will be drawn");
106         renderMobSpawnerActivationLines = setup(config, "mobSpawners", "renderMobSpawnerActivationLines", true, "If set to true a red/orange/green line will be drawn to show if the spawner is active");
107
108         drawAFKSpheres = setup(config, "afkSpot", "drawAFKSpheres", true, "If set to true afk spot spheres will be drawn.");
109         renderAFKSpawnableBlocks = setup(config, "afkSpot", "renderAFKSpawnableBlocks", true, "If set to true boxes to show spawnable blocks within the AFK sphere will be drawn.");
110         afkSpawnableBlocksRenderDistance = setup(config, "afkSpot", "afkSpawnableBlocksRenderDistance", 3, "The distance from the player where spawnable blocks within the AFK sphere will be drawn.");
111
112         config.save();
113     }
114
115     private static Configuration loadConfig() {
116         Configuration config = new Configuration(new File(configDir, "BBOutlineReloaded.cfg"));
117         config.load();
118         return config;
119     }
120
121     public static void saveConfig() {
122         Configuration config = new Configuration(new File(configDir, "BBOutlineReloaded.cfg"));
123         for (Setting<?> setting : settings) {
124             config.put(setting);
125         }
126         config.save();
127     }
128
129     private static <T> Setting<T> setup(Configuration config, String category, String settingName, T defaultValue, String comment) {
130         Setting<T> setting = config.get(category, settingName, defaultValue);
131         setting.category = category;
132         setting.name = settingName;
133         setting.comment = comment + " (default: " + defaultValue.toString() + ")";
134         settings.add(setting);
135         return setting;
136     }
137
138     public static void Toggle(Setting<Boolean> setting) {
139         setting.set(!setting.get());
140     }
141
142     public static Set<Setting<?>> getSettings() {
143         return settings;
144     }
145 }