1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
Ryan Fox 48bc060e5c
Handle config defaults less poorly 2020-08-17 00:14:07 +00:00
Ryan Fox 93f546a5ce
Add SQLite as dependency 2020-08-10 00:43:35 +00:00
Ryan Fox edd3cc8689
Pretty-print the config output 2020-08-08 00:04:18 +00:00
Ryan Fox 212f2db61a
Disable respawn anchor explosions separately
Having it tied to TNT was a bad idea, since TNT is sometimes needed for
mining and stuff.
2020-08-07 22:40:05 +00:00
3 changed files with 20 additions and 5 deletions

View File

@ -12,8 +12,10 @@ dependencies {
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modCompile "org.json:json:20200518"
modCompile "org.xerial:sqlite-jdbc:3.32.3.2"
modImplementation "com.google.code.findbugs:jsr305:3.0.2"
include "org.json:json:20200518"
include "org.xerial:sqlite-jdbc:3.32.3.2"
}
jar {

View File

@ -28,7 +28,7 @@ public abstract class MixinRespawnAnchorBlock extends Block {
@Inject(method = "explode", at = @At("HEAD"), cancellable = true)
private void onExplode(CallbackInfo ci) {
if (Config.getBool("disableTntExplosions") == true)
if (Config.getBool("disableRespawnAnchorExplosions") == true)
ci.cancel();
}
}

View File

@ -32,10 +32,13 @@ public class Config {
String jsonRaw = IOUtils.toString(is, "UTF-8");
json = new JSONObject(jsonRaw);
} else {
LOGGER.info("Config not found, creating one");
json = new JSONObject("{\"disableTntExplosions\":false,\"spawn\":[0,0,0,0,0,\"\"],\"members\":[]}");
saveConfig();
json = new JSONObject();
}
setDefault("disableTntExplosions", false);
setDefault("disableRespawnAnchorExplosions", false);
setDefault("spawn", (new PlayerPosition()).getJSON());
LOGGER.info("Configuration loaded");
}
@ -86,9 +89,19 @@ public class Config {
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() {
try (FileWriter file = new FileWriter(config)) {
file.write(JSONObject.valueToString(json));
file.write(json.toString(2));
} catch (Exception e) {
LOGGER.error("Failed to save config file");
}