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);
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.ConfigKeeper.BooleanEntry;
|
||||
import ru.betterend.config.ConfigKeeper.Entry;
|
||||
|
@ -22,25 +21,23 @@ public abstract class Config {
|
|||
protected abstract void registerEntries();
|
||||
|
||||
@Nullable
|
||||
public <E extends Entry<?>> E getEntry(String category, String key) {
|
||||
return this.configKeeper.getEntry(category, key);
|
||||
public <E extends Entry<?>> E getEntry(ConfigKey key) {
|
||||
return this.configKeeper.getEntry(key);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T getDefault(String category, String key) {
|
||||
Entry<T> entry = configKeeper.getEntry(category, key);
|
||||
public <T> T getDefault(ConfigKey key) {
|
||||
Entry<T> entry = configKeeper.getEntry(key);
|
||||
return entry != null ? entry.getDefault() : null;
|
||||
}
|
||||
|
||||
public String getString(String category, String key, String defaultValue) {
|
||||
String str = configKeeper.getValue(category, key);
|
||||
public String getString(ConfigKey key, String defaultValue) {
|
||||
String str = configKeeper.getValue(key);
|
||||
if (str == null) {
|
||||
StringEntry entry = this.configKeeper.registerEntry(category, key, new StringEntry(defaultValue));
|
||||
if (settings != null && settings.has(category)) {
|
||||
JsonObject params = JsonHelper.getObject(settings, category);
|
||||
key += " [default: " + defaultValue + "]";
|
||||
if (params.has(key)) {
|
||||
entry.fromString(JsonHelper.getString(params, key));
|
||||
StringEntry entry = this.configKeeper.registerEntry(key, new StringEntry(defaultValue));
|
||||
if (settings != null) {
|
||||
if (settings != null) {
|
||||
this.configKeeper.loadFromJson(settings, key, entry);
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
@ -48,35 +45,30 @@ public abstract class Config {
|
|||
return str != null ? str : defaultValue;
|
||||
}
|
||||
|
||||
public String getString(String category, String key) {
|
||||
String str = configKeeper.getValue(category, key);
|
||||
public String getString(ConfigKey key) {
|
||||
String str = configKeeper.getValue(key);
|
||||
return str != null ? str : "";
|
||||
}
|
||||
|
||||
public boolean setString(String category, String key, String value) {
|
||||
public boolean setString(ConfigKey key, String value) {
|
||||
try {
|
||||
StringEntry entry = configKeeper.getEntry(category, key);
|
||||
StringEntry entry = configKeeper.getEntry(key);
|
||||
if (entry == null) return false;
|
||||
entry.setValue(value);
|
||||
this.configKeeper.set(category, key, entry);
|
||||
|
||||
return true;
|
||||
} catch (NullPointerException ex) {
|
||||
BetterEnd.LOGGER.catching(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getInt(String category, String key, int defaultValue) {
|
||||
Integer val = configKeeper.getValue(category, key);
|
||||
public int getInt(ConfigKey key, int defaultValue) {
|
||||
Integer val = configKeeper.getValue(key);
|
||||
if (val == null) {
|
||||
IntegerEntry entry = this.configKeeper.registerEntry(category, key, new IntegerEntry(defaultValue));
|
||||
if (settings != null && settings.has(category)) {
|
||||
JsonObject params = JsonHelper.getObject(settings, category);
|
||||
key += " [default: " + defaultValue + "]";
|
||||
if (params.has(key)) {
|
||||
entry.fromString(JsonHelper.getString(params, key));
|
||||
IntegerEntry entry = this.configKeeper.registerEntry(key, new IntegerEntry(defaultValue));
|
||||
if (settings != null) {
|
||||
if (settings != null) {
|
||||
this.configKeeper.loadFromJson(settings, key, entry);
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
@ -84,50 +76,42 @@ public abstract class Config {
|
|||
return val != null ? val : defaultValue;
|
||||
}
|
||||
|
||||
public int getInt(String category, String key) {
|
||||
Integer val = configKeeper.getValue(category, key);
|
||||
public int getInt(ConfigKey key) {
|
||||
Integer val = configKeeper.getValue(key);
|
||||
return val != null ? val : 0;
|
||||
}
|
||||
|
||||
public boolean setInt(String category, String key, int value) {
|
||||
public boolean setInt(ConfigKey key, int value) {
|
||||
try {
|
||||
IntegerEntry entry = configKeeper.getEntry(category, key);
|
||||
IntegerEntry entry = configKeeper.getEntry(key);
|
||||
if (entry == null) return false;
|
||||
entry.setValue(value);
|
||||
this.configKeeper.set(category, key, entry);
|
||||
|
||||
return true;
|
||||
} catch (NullPointerException ex) {
|
||||
BetterEnd.LOGGER.catching(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T extends Comparable<T>> boolean setRanged(String category, String key, T value) {
|
||||
public <T extends Comparable<T>> boolean setRanged(ConfigKey key, T value) {
|
||||
try {
|
||||
RangeEntry<T> entry = configKeeper.getEntry(category, key);
|
||||
RangeEntry<T> entry = configKeeper.getEntry(key);
|
||||
if (entry == null) return false;
|
||||
entry.setValue(value);
|
||||
this.configKeeper.set(category, key, entry);
|
||||
|
||||
return true;
|
||||
} catch (NullPointerException | ClassCastException ex) {
|
||||
BetterEnd.LOGGER.catching(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public float getFloat(String category, String key, float defaultValue) {
|
||||
Float val = configKeeper.getValue(category, key);
|
||||
public float getFloat(ConfigKey key, float defaultValue) {
|
||||
Float val = configKeeper.getValue(key);
|
||||
if (val == null) {
|
||||
FloatEntry entry = this.configKeeper.registerEntry(category, key, new FloatEntry(defaultValue));
|
||||
if (settings != null && settings.has(category)) {
|
||||
JsonObject params = JsonHelper.getObject(settings, category);
|
||||
key += " [default: " + defaultValue + "]";
|
||||
if (params.has(key)) {
|
||||
entry.fromString(JsonHelper.getString(params, key));
|
||||
FloatEntry entry = this.configKeeper.registerEntry(key, new FloatEntry(defaultValue));
|
||||
if (settings != null) {
|
||||
if (settings != null) {
|
||||
this.configKeeper.loadFromJson(settings, key, entry);
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
@ -135,59 +119,49 @@ public abstract class Config {
|
|||
return val != null ? val : defaultValue;
|
||||
}
|
||||
|
||||
public float getFloat(String category, String key) {
|
||||
Float val = configKeeper.getValue(category, key);
|
||||
public float getFloat(ConfigKey key) {
|
||||
Float val = configKeeper.getValue(key);
|
||||
return val != null ? val : 0.0F;
|
||||
}
|
||||
|
||||
public boolean setFloat(String category, String key, float value) {
|
||||
public boolean setFloat(ConfigKey key, float value) {
|
||||
try {
|
||||
FloatEntry entry = configKeeper.getEntry(category, key);
|
||||
FloatEntry entry = configKeeper.getEntry(key);
|
||||
if (entry == null) return false;
|
||||
entry.setValue(value);
|
||||
this.configKeeper.set(category, key, entry);
|
||||
|
||||
return true;
|
||||
} catch (NullPointerException ex) {
|
||||
BetterEnd.LOGGER.catching(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean getBoolean(String category, String key, boolean defaultValue) {
|
||||
Boolean val = configKeeper.getValue(category, key);
|
||||
public boolean getBoolean(ConfigKey key, boolean defaultValue) {
|
||||
Boolean val = configKeeper.getValue(key);
|
||||
if (val == null) {
|
||||
BooleanEntry entry = this.configKeeper.registerEntry(category, key, new BooleanEntry(defaultValue));
|
||||
if (settings != null && settings.has(category)) {
|
||||
JsonObject params = JsonHelper.getObject(settings, category);
|
||||
key += " [default: " + defaultValue + "]";
|
||||
if (params.has(key)) {
|
||||
entry.fromString(JsonHelper.getString(params, key));
|
||||
return entry.getValue();
|
||||
}
|
||||
BooleanEntry entry = this.configKeeper.registerEntry(key, new BooleanEntry(defaultValue));
|
||||
if (settings != null) {
|
||||
this.configKeeper.loadFromJson(settings, key, entry);
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return val != null ? val : defaultValue;
|
||||
}
|
||||
|
||||
public boolean getBoolean(String category, String key) {
|
||||
Boolean val = configKeeper.getValue(category, key);
|
||||
public boolean getBoolean(ConfigKey key) {
|
||||
Boolean val = configKeeper.getValue(key);
|
||||
return val != null ? val : false;
|
||||
}
|
||||
|
||||
public boolean setBoolean(String category, String key, boolean value) {
|
||||
public boolean setBoolean(ConfigKey key, boolean value) {
|
||||
try {
|
||||
BooleanEntry entry = configKeeper.getEntry(category, key);
|
||||
BooleanEntry entry = configKeeper.getEntry(key);
|
||||
if (entry == null) return false;
|
||||
entry.setValue(value);
|
||||
this.configKeeper.set(category, key, entry);
|
||||
|
||||
return true;
|
||||
} catch (NullPointerException ex) {
|
||||
BetterEnd.LOGGER.catching(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,74 +8,83 @@ import com.google.common.collect.Maps;
|
|||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
public final class ConfigKeeper {
|
||||
|
||||
private Map<String, Map<String, Entry<?>>> configEntries = Maps.newHashMap();
|
||||
private Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
|
||||
|
||||
public JsonElement toJson(JsonObject jsonObject) {
|
||||
for (String category : configEntries.keySet()) {
|
||||
Map<String, Entry<?>> entryCategory = this.configEntries.get(category);
|
||||
JsonObject jsonCategory = new JsonObject();
|
||||
entryCategory.forEach((key, param) -> {
|
||||
key += " [default: " + param.getDefault() + "]";
|
||||
jsonCategory.addProperty(key, param.asString());
|
||||
});
|
||||
jsonObject.add(category, jsonCategory);
|
||||
}
|
||||
this.configEntries.forEach((key, entry) -> {
|
||||
Identifier categoryId = key.getCategory();
|
||||
Identifier paramId = key.getParameter();
|
||||
String group = categoryId.getPath();
|
||||
JsonObject jsonGroup;
|
||||
if (jsonObject.has(group)) {
|
||||
jsonGroup = JsonHelper.getObject(jsonObject, group);
|
||||
} else {
|
||||
jsonGroup = new JsonObject();
|
||||
jsonObject.add(group, jsonGroup);
|
||||
}
|
||||
String category = paramId.getNamespace();
|
||||
JsonObject jsonCategory;
|
||||
if (jsonGroup.has(category)) {
|
||||
jsonCategory = JsonHelper.getObject(jsonGroup, category);
|
||||
} else {
|
||||
jsonCategory = new JsonObject();
|
||||
jsonGroup.add(category, jsonCategory);
|
||||
}
|
||||
String paramKey = paramId.getPath();
|
||||
paramKey += " [default: " + entry.getDefault() + "]";
|
||||
jsonCategory.addProperty(paramKey, entry.asString());
|
||||
});
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public void fromJson(JsonObject jsonObject) {
|
||||
if (jsonObject.size() == 0) return;
|
||||
for (String category : configEntries.keySet()) {
|
||||
Map<String, Entry<?>> entryCategory = this.configEntries.get(category);
|
||||
if (!jsonObject.has(category)) continue;
|
||||
JsonObject jsonCategory = jsonObject.getAsJsonObject(category);
|
||||
entryCategory.forEach((key, param) -> {
|
||||
key += " [default: " + param.getDefault() + "]";
|
||||
if (!jsonCategory.has(key)) return;
|
||||
param.fromString(JsonHelper.getString(jsonCategory, key));
|
||||
});
|
||||
}
|
||||
this.configEntries.forEach((key, entry) -> {
|
||||
this.loadFromJson(jsonObject, key, entry);
|
||||
});
|
||||
}
|
||||
|
||||
public <E extends Entry<?>> void loadFromJson(JsonObject jsonObject, ConfigKey key, E entry) {
|
||||
Identifier categoryId = key.getCategory();
|
||||
Identifier paramId = key.getParameter();
|
||||
String group = categoryId.getPath();
|
||||
if (!jsonObject.has(group)) return;
|
||||
|
||||
JsonObject jsonGroup = JsonHelper.getObject(jsonObject, group);
|
||||
String category = paramId.getNamespace();
|
||||
if (jsonGroup.has(category)) return;
|
||||
|
||||
JsonObject jsonCategory = JsonHelper.getObject(jsonGroup, category);
|
||||
String paramKey = paramId.getPath();
|
||||
paramKey += " [default: " + entry.getDefault() + "]";
|
||||
entry.fromString(JsonHelper.getString(jsonCategory, paramKey));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E extends Entry<?>> E getEntry(String category, String key) {
|
||||
Map<String, Entry<?>> entryCategory = this.configEntries.get(category);
|
||||
if (entryCategory == null) {
|
||||
return null;
|
||||
}
|
||||
return (E) entryCategory.get(key);
|
||||
public <E extends Entry<?>> E getEntry(ConfigKey key) {
|
||||
return (E) this.configEntries.get(key);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T getValue(String category, String key) {
|
||||
Entry<T> entry = this.getEntry(category, key);
|
||||
public <T> T getValue(ConfigKey key) {
|
||||
Entry<T> entry = this.getEntry(key);
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
public void set(String category, String key, Entry<?> entry) {
|
||||
Map<String, Entry<?>> entryCategory = this.configEntries.get(category);
|
||||
if (entryCategory != null) {
|
||||
entryCategory.put(key, entry);
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Entry<?>> T registerEntry(String category, String key, T entry) {
|
||||
Map<String, Entry<?>> entryCategory = this.configEntries.get(category);
|
||||
if (entryCategory == null) {
|
||||
entryCategory = Maps.newHashMap();
|
||||
this.configEntries.put(category, entryCategory);
|
||||
}
|
||||
entryCategory.put(key, entry);
|
||||
|
||||
public <T extends Entry<?>> T registerEntry(ConfigKey key, T entry) {
|
||||
this.configEntries.put(key, entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
|
56
src/main/java/ru/betterend/config/ConfigKey.java
Normal file
56
src/main/java/ru/betterend/config/ConfigKey.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package ru.betterend.config;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ConfigKey {
|
||||
private final Identifier category;
|
||||
private final Identifier parameter;
|
||||
|
||||
public ConfigKey(Identifier category, Identifier parameter) {
|
||||
this.category = category;
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
public Identifier getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public Identifier getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((category == null) ? 0 : category.hashCode());
|
||||
result = prime * result + ((parameter == null) ? 0 : parameter.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof ConfigKey)) {
|
||||
return false;
|
||||
}
|
||||
ConfigKey other = (ConfigKey) obj;
|
||||
if (category == null) {
|
||||
if (other.category != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!category.equals(other.category)) {
|
||||
return false;
|
||||
}
|
||||
if (parameter == null) {
|
||||
if (other.parameter != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!parameter.equals(other.parameter)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
100
src/main/java/ru/betterend/config/ItemConfig.java
Normal file
100
src/main/java/ru/betterend/config/ItemConfig.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package ru.betterend.config;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import net.minecraft.util.Identifier;
|
||||
import ru.betterend.config.ConfigKeeper.Entry;
|
||||
|
||||
public class ItemConfig extends Config {
|
||||
|
||||
private final ConfigWriter writer;
|
||||
private final String group = "settings";
|
||||
|
||||
protected ItemConfig() {
|
||||
this.writer = new ConfigWriter(group);
|
||||
this.settings = this.writer.load();
|
||||
this.registerEntries();
|
||||
if (settings.size() > 0) {
|
||||
this.configKeeper.fromJson(settings);
|
||||
} else {
|
||||
this.configKeeper.toJson(settings);
|
||||
this.writer.save();
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigKey createKey(Identifier item, String category) {
|
||||
Identifier groupId = new Identifier(group, item.getNamespace());
|
||||
Identifier categoryId = new Identifier(category, item.getPath());
|
||||
return new ConfigKey(groupId, categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerEntries() {}
|
||||
|
||||
@Override
|
||||
public void saveChanges() {
|
||||
this.configKeeper.toJson(settings);
|
||||
this.writer.save();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <E extends Entry<?>> E getEntry(Identifier item, String category) {
|
||||
return this.getEntry(createKey(item, category));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T getDefault(Identifier item, String category) {
|
||||
return this.getDefault(createKey(item, category));
|
||||
}
|
||||
|
||||
public String getString(Identifier item, String category, String defaultValue) {
|
||||
return this.getString(createKey(item, category), defaultValue);
|
||||
}
|
||||
|
||||
public String getString(Identifier item, String category) {
|
||||
return this.getString(createKey(item, category));
|
||||
}
|
||||
|
||||
public boolean setString(Identifier item, String category, String value) {
|
||||
return this.setString(createKey(item, category), value);
|
||||
}
|
||||
|
||||
public int getInt(Identifier item, String category, int defaultValue) {
|
||||
return this.getInt(createKey(item, category), defaultValue);
|
||||
}
|
||||
|
||||
public int getInt(Identifier item, String category) {
|
||||
return this.getInt(createKey(item, category));
|
||||
}
|
||||
|
||||
public boolean setInt(Identifier item, String category, int value) {
|
||||
return this.setInt(createKey(item, category), value);
|
||||
}
|
||||
|
||||
public <T extends Comparable<T>> boolean setRanged(Identifier item, String category, T value) {
|
||||
return this.setRanged(createKey(item, category), value);
|
||||
}
|
||||
|
||||
public float getFloat(Identifier item, String category, float defaultValue) {
|
||||
return this.getFloat(createKey(item, category), defaultValue);
|
||||
}
|
||||
|
||||
public float getFloat(Identifier item, String category) {
|
||||
return this.getFloat(createKey(item, category));
|
||||
}
|
||||
|
||||
public boolean setFloat(Identifier item, String category, float value) {
|
||||
return this.setFloat(createKey(item, category), value);
|
||||
}
|
||||
|
||||
public boolean getBoolean(Identifier item, String category, boolean defaultValue) {
|
||||
return this.getBoolean(createKey(item, category), defaultValue);
|
||||
}
|
||||
|
||||
public boolean getBoolean(Identifier item, String category) {
|
||||
return this.getBoolean(createKey(item, category));
|
||||
}
|
||||
|
||||
public boolean setBoolean(Identifier item, String category, boolean value) {
|
||||
return this.setBoolean(createKey(item, category), value);
|
||||
}
|
||||
}
|
|
@ -1,37 +1,28 @@
|
|||
package ru.betterend.config;
|
||||
|
||||
public class MainConfig extends Config {
|
||||
|
||||
private static MainConfig instance;
|
||||
|
||||
public static MainConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MainConfig();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final ConfigWriter writer;
|
||||
|
||||
private MainConfig() {
|
||||
this.writer = new ConfigWriter("settings");
|
||||
this.settings = this.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.save();
|
||||
}
|
||||
}
|
||||
package ru.betterend.config;
|
||||
|
||||
public class MainConfig {
|
||||
public static final ItemConfig ITEM_CONFIG = getItemConfig();
|
||||
public static final BiomeConfig BIOME_CONFIG = getBiomeConfig();
|
||||
|
||||
private static ItemConfig itemConfig;
|
||||
private static BiomeConfig biomeConfig;
|
||||
|
||||
public static ItemConfig getItemConfig() {
|
||||
if (itemConfig == null) {
|
||||
itemConfig = new ItemConfig();
|
||||
}
|
||||
return itemConfig;
|
||||
}
|
||||
|
||||
public static BiomeConfig getBiomeConfig() {
|
||||
if (biomeConfig == null) {
|
||||
biomeConfig = new BiomeConfig();
|
||||
}
|
||||
return biomeConfig;
|
||||
}
|
||||
|
||||
public static void saveConfig() {
|
||||
itemConfig.saveChanges();
|
||||
biomeConfig.saveChanges();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue