json -> yaml
This commit is contained in:
parent
8800995bbd
commit
0f7bfff5d3
15 changed files with 12 additions and 1739 deletions
|
@ -1,7 +1,6 @@
|
|||
package themixray.repeating.mod;
|
||||
|
||||
import org.json.simple.parser.*;
|
||||
import org.json.simple.*;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -14,11 +13,13 @@ public class EasyConfig {
|
|||
public final Path path;
|
||||
public final File file;
|
||||
public Map<String,Object> data;
|
||||
private Yaml yaml;
|
||||
|
||||
public EasyConfig(Path path, Map<String,Object> def) {
|
||||
this.path = path;
|
||||
this.file = path.toFile();
|
||||
this.data = new HashMap<>();
|
||||
this.yaml = new Yaml();
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
|
@ -43,12 +44,12 @@ public class EasyConfig {
|
|||
write(data);
|
||||
}
|
||||
|
||||
private String toJson(Map<String,Object> p) {
|
||||
return JSONValue.toJSONString(p);
|
||||
private String toYaml(Map<String,Object> p) {
|
||||
return yaml.dump(p);
|
||||
}
|
||||
|
||||
private Map<String,Object> toMap(String j) {
|
||||
return (Map<String, Object>) JSONValue.parse(j);
|
||||
return yaml.load(j);
|
||||
}
|
||||
|
||||
private Map<String,Object> read() {
|
||||
|
@ -62,7 +63,7 @@ public class EasyConfig {
|
|||
|
||||
private void write(Map<String,Object> p) {
|
||||
try {
|
||||
Files.write(path,toJson(p).getBytes());
|
||||
Files.write(path, toYaml(p).getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -65,10 +65,10 @@ public class RepeatingMod implements ClientModInitializer {
|
|||
Map<String,Object> def = new HashMap<>();
|
||||
def.put("record_blocks_limit", record_blocks_limit);
|
||||
def.put("record_time_limit", record_time_limit);
|
||||
conf = new EasyConfig(new File(loader.getConfigDir().toFile(),"repeating-mod.json").toPath(),def);
|
||||
conf = new EasyConfig(new File(loader.getConfigDir().toFile(),"repeating-mod.yml").toPath(),def);
|
||||
|
||||
record_blocks_limit = (double) conf.data.get("record_blocks_limit");
|
||||
record_time_limit = (long) conf.data.get("record_time_limit");
|
||||
record_time_limit = (Integer) conf.data.get("record_time_limit");
|
||||
|
||||
menu_key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"key.repeating-mod.menu",InputUtil.Type.KEYSYM,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue