Bladeren bron

Expose Config

Lortseam 4 jaren geleden
bovenliggende
commit
54d1fe445e

+ 1 - 1
example/src/main/java/me/lortseam/completeconfig/example/Settings.java

@@ -14,7 +14,7 @@ public final class Settings extends Config implements ConfigContainer {
 
     Settings() {
         super(ExampleMod.MOD_ID, false);
-        resolve(this);
+        add(this);
         load();
     }
 

+ 1 - 1
lib/src/main/java/me/lortseam/completeconfig/data/BaseCollection.java

@@ -73,7 +73,7 @@ abstract class BaseCollection implements ParentDataPart, Translatable {
         resolve(container.getTransitives());
     }
 
-    protected void resolve(ConfigContainer... containers) {
+    void resolve(ConfigContainer... containers) {
         for (ConfigContainer container : containers) {
             if (container instanceof ConfigGroup) {
                 collections.resolve((ConfigGroup) container);

+ 13 - 8
lib/src/main/java/me/lortseam/completeconfig/data/Config.java

@@ -47,7 +47,7 @@ public class Config extends BaseCollection {
      * @param branch the branch
      * @param saveOnExit whether to save the config when the client or server stops
      */
-    protected Config(String modId, String[] branch, boolean saveOnExit) {
+    public Config(String modId, String[] branch, boolean saveOnExit) {
         source = new ConfigSource(modId, branch);
         ConfigRegistry.register(this);
         if (saveOnExit) {
@@ -61,7 +61,7 @@ public class Config extends BaseCollection {
      * @param modId the ID of the mod creating the config
      * @param saveOnExit whether to save the config when the client or server stops
      */
-    protected Config(String modId, boolean saveOnExit) {
+    public Config(String modId, boolean saveOnExit) {
         this(modId, new String[0], saveOnExit);
     }
 
@@ -85,9 +85,16 @@ public class Config extends BaseCollection {
         return translation;
     }
 
-    public void load() {
-        if(isEmpty()) return;
-        source.load(this);
+    public Config add(ConfigContainer... containers) {
+        resolve(containers);
+        return this;
+    }
+
+    public Config load() {
+        if(!isEmpty()) {
+            source.load(this);
+        }
+        return this;
     }
 
     /**
@@ -176,9 +183,7 @@ public class Config extends BaseCollection {
          */
         @Deprecated
         public Config build() {
-            Config config = new Config(modId, branch, saveOnExit);
-            config.resolve(children.toArray(new ConfigContainer[0]));
-            config.load();
+            Config config = new Config(modId, branch, saveOnExit).add(children.toArray(new ConfigContainer[0])).load();
             if (main) {
                 ConfigRegistry.setMainConfig(config);
             }