Handle config defaults less poorly
This commit is contained in:
parent
93f546a5ce
commit
48bc060e5c
@ -32,10 +32,13 @@ public class Config {
|
|||||||
String jsonRaw = IOUtils.toString(is, "UTF-8");
|
String jsonRaw = IOUtils.toString(is, "UTF-8");
|
||||||
json = new JSONObject(jsonRaw);
|
json = new JSONObject(jsonRaw);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("Config not found, creating one");
|
json = new JSONObject();
|
||||||
json = new JSONObject("{\"disableTntExplosions\":false,\"disableRespawnAnchorExplosions\":false,\"spawn\":[0,0,0,0,0,\"\"],\"members\":[]}");
|
|
||||||
saveConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setDefault("disableTntExplosions", false);
|
||||||
|
setDefault("disableRespawnAnchorExplosions", false);
|
||||||
|
setDefault("spawn", (new PlayerPosition()).getJSON());
|
||||||
|
|
||||||
LOGGER.info("Configuration loaded");
|
LOGGER.info("Configuration loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +89,16 @@ public class Config {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setDefault(String key, JSONArray data) {
|
||||||
|
if (!json.has(key))
|
||||||
|
json.put(key, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setDefault(String key, Boolean data) {
|
||||||
|
if (!json.has(key))
|
||||||
|
json.put(key, data);
|
||||||
|
}
|
||||||
|
|
||||||
private static void saveConfig() {
|
private static void saveConfig() {
|
||||||
try (FileWriter file = new FileWriter(config)) {
|
try (FileWriter file = new FileWriter(config)) {
|
||||||
file.write(json.toString(2));
|
file.write(json.toString(2));
|
||||||
|
Loading…
Reference in New Issue
Block a user