|
@@ -12,7 +12,6 @@ import net.fabricmc.api.Environment;
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
import net.fabricmc.loader.api.metadata.ModMetadata;
|
|
import net.fabricmc.loader.api.metadata.ModMetadata;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
import java.util.LinkedHashSet;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
@@ -20,7 +19,7 @@ import java.util.Objects;
|
|
* The base config class. Inherit this class to create a config for your mod.
|
|
* The base config class. Inherit this class to create a config for your mod.
|
|
*/
|
|
*/
|
|
@Log4j2(topic = "CompleteConfig")
|
|
@Log4j2(topic = "CompleteConfig")
|
|
-public abstract class Config extends BaseCollection implements ConfigContainer {
|
|
|
|
|
|
+public abstract class Config extends BaseCollection {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Creates a new config builder for the specified mod.
|
|
* Creates a new config builder for the specified mod.
|
|
@@ -34,7 +33,6 @@ public abstract class Config extends BaseCollection implements ConfigContainer {
|
|
return new Builder(modId);
|
|
return new Builder(modId);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
@Getter(AccessLevel.PACKAGE)
|
|
@Getter(AccessLevel.PACKAGE)
|
|
private final ConfigSource source;
|
|
private final ConfigSource source;
|
|
@Environment(EnvType.CLIENT)
|
|
@Environment(EnvType.CLIENT)
|
|
@@ -52,12 +50,6 @@ public abstract class Config extends BaseCollection implements ConfigContainer {
|
|
protected Config(String modId, String[] branch, boolean saveOnExit) {
|
|
protected Config(String modId, String[] branch, boolean saveOnExit) {
|
|
source = new ConfigSource(modId, branch);
|
|
source = new ConfigSource(modId, branch);
|
|
ConfigRegistry.register(this);
|
|
ConfigRegistry.register(this);
|
|
- resolveContainer(this);
|
|
|
|
- if (isEmpty()) {
|
|
|
|
- logger.warn("Empty config: " + modId + " " + Arrays.toString(branch));
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- load();
|
|
|
|
if (saveOnExit) {
|
|
if (saveOnExit) {
|
|
Runtime.getRuntime().addShutdownHook(new Thread(this::save));
|
|
Runtime.getRuntime().addShutdownHook(new Thread(this::save));
|
|
}
|
|
}
|
|
@@ -93,7 +85,8 @@ public abstract class Config extends BaseCollection implements ConfigContainer {
|
|
return translation;
|
|
return translation;
|
|
}
|
|
}
|
|
|
|
|
|
- private void load() {
|
|
|
|
|
|
+ public void load() {
|
|
|
|
+ if(isEmpty()) return;
|
|
source.load(this);
|
|
source.load(this);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -101,6 +94,7 @@ public abstract class Config extends BaseCollection implements ConfigContainer {
|
|
* Saves the config.
|
|
* Saves the config.
|
|
*/
|
|
*/
|
|
public void save() {
|
|
public void save() {
|
|
|
|
+ if(isEmpty()) return;
|
|
source.save(this);
|
|
source.save(this);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -182,12 +176,9 @@ public abstract class Config extends BaseCollection implements ConfigContainer {
|
|
*/
|
|
*/
|
|
@Deprecated
|
|
@Deprecated
|
|
public Config build() {
|
|
public Config build() {
|
|
- Config config = new Config(modId, branch, saveOnExit) {
|
|
|
|
- @Override
|
|
|
|
- public ConfigContainer[] getTransitives() {
|
|
|
|
- return children.toArray(new ConfigContainer[0]);
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+ Config config = new Config(modId, branch, saveOnExit) {};
|
|
|
|
+ config.resolve(children.toArray(new ConfigContainer[0]));
|
|
|
|
+ config.load();
|
|
if (main) {
|
|
if (main) {
|
|
ConfigRegistry.setMainConfig(config);
|
|
ConfigRegistry.setMainConfig(config);
|
|
}
|
|
}
|