One more config
This commit is contained in:
parent
bb0e54ad25
commit
ef333d4dca
6 changed files with 399 additions and 290 deletions
|
@ -2,8 +2,6 @@ package ru.betterend.config;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.config.ConfigKeeper.BooleanEntry;
|
import ru.betterend.config.ConfigKeeper.BooleanEntry;
|
||||||
import ru.betterend.config.ConfigKeeper.Entry;
|
import ru.betterend.config.ConfigKeeper.Entry;
|
||||||
|
@ -15,20 +13,16 @@ import ru.betterend.config.ConfigKeeper.StringEntry;
|
||||||
public abstract class Config {
|
public abstract class Config {
|
||||||
|
|
||||||
protected final ConfigKeeper keeper;
|
protected final ConfigKeeper keeper;
|
||||||
protected final ConfigWriter writer;
|
|
||||||
|
|
||||||
protected abstract void registerEntries();
|
protected abstract void registerEntries();
|
||||||
|
|
||||||
public Config(String group) {
|
public Config(String group) {
|
||||||
this.writer = new ConfigWriter(group);
|
this.keeper = new ConfigKeeper(group);
|
||||||
JsonObject settings = writer.load();
|
|
||||||
this.keeper = new ConfigKeeper(settings);
|
|
||||||
this.registerEntries();
|
this.registerEntries();
|
||||||
this.writer.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveChanges() {
|
public void saveChanges() {
|
||||||
this.writer.save();
|
this.keeper.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -18,14 +18,50 @@ import ru.betterend.util.JsonFactory;
|
||||||
public final class ConfigKeeper {
|
public final class ConfigKeeper {
|
||||||
|
|
||||||
private Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
|
private Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
|
||||||
private final JsonObject configObject;
|
|
||||||
|
|
||||||
public ConfigKeeper(JsonObject config) {
|
private final JsonObject configObject;
|
||||||
this.configObject = config;
|
private final ConfigWriter writer;
|
||||||
|
|
||||||
|
private boolean changed = false;
|
||||||
|
|
||||||
|
public ConfigKeeper(String group) {
|
||||||
|
this.writer = new ConfigWriter(group);
|
||||||
|
this.configObject = writer.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
if (!changed) return;
|
||||||
|
this.writer.save();
|
||||||
|
this.changed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T, E extends Entry<T>> boolean has(ConfigKey key, E entry) {
|
||||||
|
if (configObject == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String group = key.getOwner();
|
||||||
|
if (!configObject.has(group)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JsonObject jsonGroup = JsonHelper.getObject(configObject, group);
|
||||||
|
String category = key.getCategory();
|
||||||
|
if (!jsonGroup.has(category)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JsonObject jsonCategory = JsonHelper.getObject(jsonGroup, category);
|
||||||
|
String paramKey = key.getEntry();
|
||||||
|
paramKey += " [default: " + entry.getDefault() + "]";
|
||||||
|
return jsonCategory.has(paramKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T, E extends Entry<T>> void storeValue(ConfigKey key, E entry, T value) {
|
private <T, E extends Entry<T>> void storeValue(ConfigKey key, E entry, T value) {
|
||||||
if (configObject == null) return;
|
if (configObject == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (has(key, entry)) {
|
||||||
|
T val = entry.getValue();
|
||||||
|
if (value.equals(val)) return;
|
||||||
|
}
|
||||||
|
|
||||||
String group = key.getOwner();
|
String group = key.getOwner();
|
||||||
JsonObject jsonGroup;
|
JsonObject jsonGroup;
|
||||||
|
@ -46,30 +82,20 @@ public final class ConfigKeeper {
|
||||||
String paramKey = key.getEntry();
|
String paramKey = key.getEntry();
|
||||||
paramKey += " [default: " + entry.getDefault() + "]";
|
paramKey += " [default: " + entry.getDefault() + "]";
|
||||||
entry.toJson(jsonCategory, paramKey, value);
|
entry.toJson(jsonCategory, paramKey, value);
|
||||||
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T, E extends Entry<T>> T getValue(ConfigKey key, E entry) {
|
private <T, E extends Entry<T>> T getValue(ConfigKey key, E entry) {
|
||||||
if (configObject == null) {
|
if (!has(key, entry)) {
|
||||||
return entry.getDefault();
|
return entry.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
String group = key.getOwner();
|
String group = key.getOwner();
|
||||||
if (!configObject.has(group)) {
|
|
||||||
return entry.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject jsonGroup = JsonHelper.getObject(configObject, group);
|
|
||||||
String category = key.getCategory();
|
String category = key.getCategory();
|
||||||
if (!jsonGroup.has(category)) {
|
JsonObject jsonGroup = JsonHelper.getObject(configObject, group);
|
||||||
return entry.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject jsonCategory = JsonHelper.getObject(jsonGroup, category);
|
JsonObject jsonCategory = JsonHelper.getObject(jsonGroup, category);
|
||||||
|
|
||||||
String paramKey = key.getEntry();
|
String paramKey = key.getEntry();
|
||||||
paramKey += " [default: " + entry.getDefault() + "]";
|
paramKey += " [default: " + entry.getDefault() + "]";
|
||||||
if (!jsonCategory.has(paramKey)) {
|
|
||||||
return entry.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry.fromJson(jsonCategory.get(paramKey));
|
return entry.fromJson(jsonCategory.get(paramKey));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package ru.betterend.config;
|
package ru.betterend.config;
|
||||||
|
|
||||||
public class Configs {
|
public class Configs {
|
||||||
public static final IdConfig ITEM_CONFIG = new CategoryConfig("items");
|
|
||||||
public static final IdConfig BLOCK_CONFIG = new CategoryConfig("blocks");
|
|
||||||
public static final IdConfig ENTITY_CONFIG = new CategoryConfig("entities");
|
public static final IdConfig ENTITY_CONFIG = new CategoryConfig("entities");
|
||||||
|
public static final IdConfig BLOCK_CONFIG = new CategoryConfig("blocks");
|
||||||
|
public static final SimpleConfig GENERAL = new SimpleConfig("settings");
|
||||||
|
public static final IdConfig ITEM_CONFIG = new CategoryConfig("items");
|
||||||
public static final IdConfig BIOME_CONFIG = new EntryConfig("biomes");
|
public static final IdConfig BIOME_CONFIG = new EntryConfig("biomes");
|
||||||
public static final SimpleConfig GENERATOR_CONFIG = new SimpleConfig("generator");
|
|
||||||
|
|
||||||
public static void saveConfigs() {
|
public static void saveConfigs() {
|
||||||
ITEM_CONFIG.saveChanges();
|
ENTITY_CONFIG.saveChanges();
|
||||||
BLOCK_CONFIG.saveChanges();
|
BLOCK_CONFIG.saveChanges();
|
||||||
BIOME_CONFIG.saveChanges();
|
BIOME_CONFIG.saveChanges();
|
||||||
ENTITY_CONFIG.saveChanges();
|
ITEM_CONFIG.saveChanges();
|
||||||
GENERATOR_CONFIG.save();
|
GENERAL.saveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
257
src/main/java/ru/betterend/config/DeprecatedConfig.java
Normal file
257
src/main/java/ru/betterend/config/DeprecatedConfig.java
Normal file
|
@ -0,0 +1,257 @@
|
||||||
|
package ru.betterend.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import ru.betterend.BetterEnd;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public final class DeprecatedConfig {
|
||||||
|
private boolean rewrite = false;
|
||||||
|
private final String name;
|
||||||
|
private JsonObject config;
|
||||||
|
|
||||||
|
public DeprecatedConfig(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load() {
|
||||||
|
if (config == null) {
|
||||||
|
File file = getFolder();
|
||||||
|
if (!file.exists())
|
||||||
|
file.mkdirs();
|
||||||
|
file = getFile();
|
||||||
|
if (file.exists()) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
try {
|
||||||
|
Reader reader = new FileReader(file);
|
||||||
|
config = gson.fromJson(reader, JsonObject.class);
|
||||||
|
if (config == null) {
|
||||||
|
config = new JsonObject();
|
||||||
|
rewrite = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rewrite = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
config = new JsonObject();
|
||||||
|
rewrite = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
config = new JsonObject();
|
||||||
|
rewrite = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
if (rewrite) {
|
||||||
|
File file = getFolder();
|
||||||
|
if (!file.exists())
|
||||||
|
file.mkdirs();
|
||||||
|
file = getFile();
|
||||||
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
try {
|
||||||
|
FileWriter writer = new FileWriter(file);
|
||||||
|
String gstring = gson.toJson(config);
|
||||||
|
writer.write(gstring);
|
||||||
|
writer.flush();
|
||||||
|
writer.close();
|
||||||
|
rewrite = false;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getFile() {
|
||||||
|
return new File(String.format("./config/%s/%s.json", BetterEnd.MOD_ID, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getFolder() {
|
||||||
|
return new File("./config/" + BetterEnd.MOD_ID + "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBoolean(String groups, String name, boolean def) {
|
||||||
|
load();
|
||||||
|
name += "[def: " + def + "]";
|
||||||
|
|
||||||
|
JsonObject group = getGroup(groups);
|
||||||
|
JsonElement element = group.get(name);
|
||||||
|
|
||||||
|
if (element != null) {
|
||||||
|
return element.getAsBoolean();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
group.addProperty(name, def);
|
||||||
|
rewrite = true;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoolean(String groups, String name, boolean def, boolean value) {
|
||||||
|
name += "[def: " + def + "]";
|
||||||
|
|
||||||
|
JsonObject group = getGroup(groups);
|
||||||
|
group.addProperty(name, value);
|
||||||
|
|
||||||
|
rewrite = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getFloat(String groups, String name, float def) {
|
||||||
|
load();
|
||||||
|
name += "[def: " + def + "]";
|
||||||
|
|
||||||
|
JsonObject group = getGroup(groups);
|
||||||
|
JsonElement element = group.get(name);
|
||||||
|
|
||||||
|
if (element != null) {
|
||||||
|
return element.getAsFloat();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
group.addProperty(name, def);
|
||||||
|
rewrite = true;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFloat(String groups, String name, float def, float value) {
|
||||||
|
name += "[def: " + def + "]";
|
||||||
|
|
||||||
|
JsonObject group = getGroup(groups);
|
||||||
|
group.addProperty(name, value);
|
||||||
|
|
||||||
|
rewrite = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInt(String groups, String name, int def) {
|
||||||
|
load();
|
||||||
|
name += "[def: " + def + "]";
|
||||||
|
|
||||||
|
JsonObject group = getGroup(groups);
|
||||||
|
JsonElement element = group.get(name);
|
||||||
|
|
||||||
|
if (element != null) {
|
||||||
|
return element.getAsInt();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
group.addProperty(name, def);
|
||||||
|
rewrite = true;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String groups, String name, String def) {
|
||||||
|
load();
|
||||||
|
name += "[def: " + def + "]";
|
||||||
|
|
||||||
|
JsonObject group = getGroup(groups);
|
||||||
|
JsonElement element = group.get(name);
|
||||||
|
|
||||||
|
if (element != null) {
|
||||||
|
return element.getAsString();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
group.addProperty(name, def);
|
||||||
|
rewrite = true;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInt(String groups, String name, int def, int value) {
|
||||||
|
name += "[def: " + def + "]";
|
||||||
|
|
||||||
|
JsonObject group = getGroup(groups);
|
||||||
|
group.addProperty(name, value);
|
||||||
|
|
||||||
|
rewrite = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStringLoad(String groups, String name, String value) {
|
||||||
|
JsonObject group = getGroup(groups);
|
||||||
|
group.addProperty(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getStringArray(String groups, String name, String[] def) {
|
||||||
|
load();
|
||||||
|
|
||||||
|
JsonObject group = getGroup(groups);
|
||||||
|
JsonElement element = group.get(name);
|
||||||
|
|
||||||
|
if (element != null) {
|
||||||
|
return toStringArray(element.getAsJsonArray());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
group.add(name, toJsonArray(def));
|
||||||
|
rewrite = true;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] toStringArray(JsonArray array) {
|
||||||
|
load();
|
||||||
|
String[] result = new String[array.size()];
|
||||||
|
for (int i = 0; i < array.size(); i++)
|
||||||
|
result[i] = array.get(i).getAsString();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonArray toJsonArray(String[] array) {
|
||||||
|
load();
|
||||||
|
JsonArray result = new JsonArray();
|
||||||
|
for (String s : array)
|
||||||
|
result.add(s);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObject getGroup(String groups) {
|
||||||
|
JsonObject obj = config;
|
||||||
|
String[] groupsArr = groups.split("\\.");
|
||||||
|
for (String group : groupsArr) {
|
||||||
|
JsonObject jGroup = obj.getAsJsonObject(group);
|
||||||
|
if (jGroup == null) {
|
||||||
|
jGroup = new JsonObject();
|
||||||
|
obj.add(group, jGroup);
|
||||||
|
}
|
||||||
|
obj = jGroup;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getBaseGroups() {
|
||||||
|
List<String> groups = new ArrayList<String>();
|
||||||
|
Iterator<Entry<String, JsonElement>> iterator = config.entrySet().iterator();
|
||||||
|
iterator.forEachRemaining((element) -> {
|
||||||
|
groups.add(element.getKey());
|
||||||
|
});
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Entry<String, JsonElement>> getGroupMembers(JsonObject group) {
|
||||||
|
List<Entry<String, JsonElement>> result = new ArrayList<Entry<String, JsonElement>>();
|
||||||
|
result.addAll(group.entrySet());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void markToSave() {
|
||||||
|
rewrite = true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,256 +1,88 @@
|
||||||
package ru.betterend.config;
|
package ru.betterend.config;
|
||||||
|
|
||||||
import java.io.File;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
import ru.betterend.BetterEnd;
|
||||||
import java.io.FileWriter;
|
import ru.betterend.config.ConfigKeeper.Entry;
|
||||||
import java.io.IOException;
|
import ru.betterend.config.ConfigKeeper.FloatRange;
|
||||||
import java.io.Reader;
|
import ru.betterend.config.ConfigKeeper.IntegerRange;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
public class SimpleConfig extends Config {
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
public SimpleConfig(String group) {
|
||||||
|
super(group);
|
||||||
import com.google.gson.Gson;
|
}
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonArray;
|
@Override
|
||||||
import com.google.gson.JsonElement;
|
protected void registerEntries() {}
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
protected ConfigKey createKey(String category, String key) {
|
||||||
import ru.betterend.BetterEnd;
|
return new ConfigKey(BetterEnd.MOD_ID, category, key);
|
||||||
|
}
|
||||||
public final class SimpleConfig {
|
|
||||||
private boolean rewrite = false;
|
@Nullable
|
||||||
private final String name;
|
public <T, E extends Entry<T>> E getEntry(String category, String key, Class<E> type) {
|
||||||
private JsonObject config;
|
return this.getEntry(createKey(category, key), type);
|
||||||
|
}
|
||||||
public SimpleConfig(String name) {
|
|
||||||
this.name = name;
|
@Nullable
|
||||||
}
|
public <T, E extends Entry<T>> T getDefault(String category, String key, Class<E> type) {
|
||||||
|
return this.getDefault(createKey(category, key), type);
|
||||||
private void load() {
|
}
|
||||||
if (config == null) {
|
|
||||||
File file = getFolder();
|
public String getString(String category, String key, String defaultValue) {
|
||||||
if (!file.exists())
|
return this.getString(createKey(category, key), defaultValue);
|
||||||
file.mkdirs();
|
}
|
||||||
file = getFile();
|
|
||||||
if (file.exists()) {
|
public String getString(String category, String key) {
|
||||||
Gson gson = new Gson();
|
return this.getString(createKey(category, key));
|
||||||
try {
|
}
|
||||||
Reader reader = new FileReader(file);
|
|
||||||
config = gson.fromJson(reader, JsonObject.class);
|
public boolean setString(String category, String key, String value) {
|
||||||
if (config == null) {
|
return this.setString(createKey(category, key), value);
|
||||||
config = new JsonObject();
|
}
|
||||||
rewrite = true;
|
|
||||||
}
|
public int getInt(String category, String key, int defaultValue) {
|
||||||
else {
|
return this.getInt(createKey(category, key), defaultValue);
|
||||||
rewrite = false;
|
}
|
||||||
}
|
|
||||||
}
|
public int getInt(String category, String key) {
|
||||||
catch (FileNotFoundException e) {
|
return this.getInt(createKey(category, key));
|
||||||
e.printStackTrace();
|
}
|
||||||
config = new JsonObject();
|
|
||||||
rewrite = true;
|
public boolean setInt(String category, String key, int value) {
|
||||||
}
|
return this.setInt(createKey(category, key), value);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
config = new JsonObject();
|
public boolean setRangedInt(String category, String key, int value) {
|
||||||
rewrite = true;
|
return this.setRanged(createKey(category, key), value, IntegerRange.class);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
public boolean setRangedFloat(String category, String key, float value) {
|
||||||
|
return this.setRanged(createKey(category, key), value, FloatRange.class);
|
||||||
public void save() {
|
}
|
||||||
if (rewrite) {
|
|
||||||
File file = getFolder();
|
public float getFloat(String category, String key, float defaultValue) {
|
||||||
if (!file.exists())
|
return this.getFloat(createKey(category, key), defaultValue);
|
||||||
file.mkdirs();
|
}
|
||||||
file = getFile();
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
public float getFloat(String category, String key) {
|
||||||
try {
|
return this.getFloat(createKey(category, key));
|
||||||
FileWriter writer = new FileWriter(file);
|
}
|
||||||
String gstring = gson.toJson(config);
|
|
||||||
writer.write(gstring);
|
public boolean setFloat(String category, String key, float value) {
|
||||||
writer.flush();
|
return this.setFloat(createKey(category, key), value);
|
||||||
writer.close();
|
}
|
||||||
rewrite = false;
|
|
||||||
}
|
public boolean getBoolean(String category, String key, boolean defaultValue) {
|
||||||
catch (IOException e) {
|
return this.getBoolean(createKey(category, key), defaultValue);
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
|
||||||
}
|
public boolean getBoolean(String category, String key) {
|
||||||
}
|
return this.getBoolean(createKey(category, key));
|
||||||
|
}
|
||||||
private File getFile() {
|
|
||||||
return new File(String.format("./config/%s/%s.json", BetterEnd.MOD_ID, name));
|
public boolean setBoolean(String category, String key, boolean value) {
|
||||||
}
|
return this.setBoolean(createKey(category, key), value);
|
||||||
|
}
|
||||||
private File getFolder() {
|
}
|
||||||
return new File("./config/" + BetterEnd.MOD_ID + "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getBoolean(String groups, String name, boolean def) {
|
|
||||||
load();
|
|
||||||
name += "[def: " + def + "]";
|
|
||||||
|
|
||||||
JsonObject group = getGroup(groups);
|
|
||||||
JsonElement element = group.get(name);
|
|
||||||
|
|
||||||
if (element != null) {
|
|
||||||
return element.getAsBoolean();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
group.addProperty(name, def);
|
|
||||||
rewrite = true;
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBoolean(String groups, String name, boolean def, boolean value) {
|
|
||||||
name += "[def: " + def + "]";
|
|
||||||
|
|
||||||
JsonObject group = getGroup(groups);
|
|
||||||
group.addProperty(name, value);
|
|
||||||
|
|
||||||
rewrite = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getFloat(String groups, String name, float def) {
|
|
||||||
load();
|
|
||||||
name += "[def: " + def + "]";
|
|
||||||
|
|
||||||
JsonObject group = getGroup(groups);
|
|
||||||
JsonElement element = group.get(name);
|
|
||||||
|
|
||||||
if (element != null) {
|
|
||||||
return element.getAsFloat();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
group.addProperty(name, def);
|
|
||||||
rewrite = true;
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFloat(String groups, String name, float def, float value) {
|
|
||||||
name += "[def: " + def + "]";
|
|
||||||
|
|
||||||
JsonObject group = getGroup(groups);
|
|
||||||
group.addProperty(name, value);
|
|
||||||
|
|
||||||
rewrite = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInt(String groups, String name, int def) {
|
|
||||||
load();
|
|
||||||
name += "[def: " + def + "]";
|
|
||||||
|
|
||||||
JsonObject group = getGroup(groups);
|
|
||||||
JsonElement element = group.get(name);
|
|
||||||
|
|
||||||
if (element != null) {
|
|
||||||
return element.getAsInt();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
group.addProperty(name, def);
|
|
||||||
rewrite = true;
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString(String groups, String name, String def) {
|
|
||||||
load();
|
|
||||||
name += "[def: " + def + "]";
|
|
||||||
|
|
||||||
JsonObject group = getGroup(groups);
|
|
||||||
JsonElement element = group.get(name);
|
|
||||||
|
|
||||||
if (element != null) {
|
|
||||||
return element.getAsString();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
group.addProperty(name, def);
|
|
||||||
rewrite = true;
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInt(String groups, String name, int def, int value) {
|
|
||||||
name += "[def: " + def + "]";
|
|
||||||
|
|
||||||
JsonObject group = getGroup(groups);
|
|
||||||
group.addProperty(name, value);
|
|
||||||
|
|
||||||
rewrite = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStringLoad(String groups, String name, String value) {
|
|
||||||
JsonObject group = getGroup(groups);
|
|
||||||
group.addProperty(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getStringArray(String groups, String name, String[] def) {
|
|
||||||
load();
|
|
||||||
|
|
||||||
JsonObject group = getGroup(groups);
|
|
||||||
JsonElement element = group.get(name);
|
|
||||||
|
|
||||||
if (element != null) {
|
|
||||||
return toStringArray(element.getAsJsonArray());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
group.add(name, toJsonArray(def));
|
|
||||||
rewrite = true;
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] toStringArray(JsonArray array) {
|
|
||||||
load();
|
|
||||||
String[] result = new String[array.size()];
|
|
||||||
for (int i = 0; i < array.size(); i++)
|
|
||||||
result[i] = array.get(i).getAsString();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JsonArray toJsonArray(String[] array) {
|
|
||||||
load();
|
|
||||||
JsonArray result = new JsonArray();
|
|
||||||
for (String s : array)
|
|
||||||
result.add(s);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonObject getGroup(String groups) {
|
|
||||||
JsonObject obj = config;
|
|
||||||
String[] groupsArr = groups.split("\\.");
|
|
||||||
for (String group : groupsArr) {
|
|
||||||
JsonObject jGroup = obj.getAsJsonObject(group);
|
|
||||||
if (jGroup == null) {
|
|
||||||
jGroup = new JsonObject();
|
|
||||||
obj.add(group, jGroup);
|
|
||||||
}
|
|
||||||
obj = jGroup;
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getBaseGroups() {
|
|
||||||
List<String> groups = new ArrayList<String>();
|
|
||||||
Iterator<Entry<String, JsonElement>> iterator = config.entrySet().iterator();
|
|
||||||
iterator.forEachRemaining((element) -> {
|
|
||||||
groups.add(element.getKey());
|
|
||||||
});
|
|
||||||
return groups;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Entry<String, JsonElement>> getGroupMembers(JsonObject group) {
|
|
||||||
List<Entry<String, JsonElement>> result = new ArrayList<Entry<String, JsonElement>>();
|
|
||||||
result.addAll(group.entrySet());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void markToSave() {
|
|
||||||
rewrite = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ public class TerrainGenerator {
|
||||||
private static boolean noRingVoid;
|
private static boolean noRingVoid;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
newGenerator = Configs.GENERATOR_CONFIG.getBoolean("generator", "useNewGenerator", false);
|
newGenerator = Configs.GENERAL.getBoolean("generator", "useNewGenerator", false);
|
||||||
noRingVoid = Configs.GENERATOR_CONFIG.getBoolean("generator", "noRingVoid", false);
|
noRingVoid = Configs.GENERAL.getBoolean("generator", "noRingVoid", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initNoise(long seed) {
|
public static void initNoise(long seed) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue