Config refactor
This commit is contained in:
parent
7f2bad86ca
commit
0f12a477e0
10 changed files with 408 additions and 265 deletions
102
src/main/java/ru/betterend/config/BiomeConfig.java
Normal file
102
src/main/java/ru/betterend/config/BiomeConfig.java
Normal file
|
@ -0,0 +1,102 @@
|
|||
package ru.betterend.config;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import ru.betterend.config.ConfigKeeper.Entry;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
|
||||
public class BiomeConfig extends Config {
|
||||
|
||||
private final ConfigWriter writer;
|
||||
private final String group = "biomes";
|
||||
|
||||
protected BiomeConfig() {
|
||||
this.writer = new ConfigWriter(group);
|
||||
this.settings = writer.load();
|
||||
this.registerEntries();
|
||||
if (settings.size() > 0) {
|
||||
this.configKeeper.fromJson(settings);
|
||||
} else {
|
||||
this.configKeeper.toJson(settings);
|
||||
this.writer.save();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerEntries() {}
|
||||
|
||||
@Override
|
||||
public void saveChanges() {
|
||||
this.configKeeper.toJson(settings);
|
||||
this.writer.saveConfig();
|
||||
}
|
||||
|
||||
private ConfigKey createKey(Identifier biome, String key) {
|
||||
Identifier groupId = new Identifier(group, biome.getNamespace());
|
||||
Identifier categoryId = new Identifier(biome.getPath(), key);
|
||||
return new ConfigKey(groupId, categoryId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <E extends Entry<?>> E getEntry(EndBiome biome, String key) {
|
||||
return this.getEntry(createKey(biome.getID(), key));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T getDefault(EndBiome biome, String key) {
|
||||
return this.getDefault(createKey(biome.getID(), key));
|
||||
}
|
||||
|
||||
public String getString(EndBiome biome, String key, String defaultValue) {
|
||||
return this.getString(createKey(biome.getID(), key), defaultValue);
|
||||
}
|
||||
|
||||
public String getString(EndBiome biome, String key) {
|
||||
return this.getString(createKey(biome.getID(), key));
|
||||
}
|
||||
|
||||
public boolean setString(EndBiome biome, String key, String value) {
|
||||
return this.setString(createKey(biome.getID(), key), value);
|
||||
}
|
||||
|
||||
public int getInt(EndBiome biome, String key, int defaultValue) {
|
||||
return this.getInt(createKey(biome.getID(), key), defaultValue);
|
||||
}
|
||||
|
||||
public int getInt(EndBiome biome, String key) {
|
||||
return this.getInt(createKey(biome.getID(), key));
|
||||
}
|
||||
|
||||
public boolean setInt(EndBiome biome, String key, int value) {
|
||||
return this.setInt(createKey(biome.getID(), key), value);
|
||||
}
|
||||
|
||||
public <T extends Comparable<T>> boolean setRanged(EndBiome biome, String key, T value) {
|
||||
return this.setRanged(createKey(biome.getID(), key), value);
|
||||
}
|
||||
|
||||
public float getFloat(EndBiome biome, String key, float defaultValue) {
|
||||
return this.getFloat(createKey(biome.getID(), key), defaultValue);
|
||||
}
|
||||
|
||||
public float getFloat(EndBiome biome, String key) {
|
||||
return this.getFloat(createKey(biome.getID(), key));
|
||||
}
|
||||
|
||||
public boolean setFloat(EndBiome biome, String key, float value) {
|
||||
return this.setFloat(createKey(biome.getID(), key), value);
|
||||
}
|
||||
|
||||
public boolean getBoolean(EndBiome biome, String key, boolean defaultValue) {
|
||||
return this.getBoolean(createKey(biome.getID(), key), defaultValue);
|
||||
}
|
||||
|
||||
public boolean getBoolean(EndBiome biome, String key) {
|
||||
return this.getBoolean(createKey(biome.getID(), key));
|
||||
}
|
||||
|
||||
public boolean setBoolean(EndBiome biome, String key, boolean value) {
|
||||
return this.setBoolean(createKey(biome.getID(), key), value);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue