Fixed some horrible JSON hacks

This commit is contained in:
Anuken
2026-07-01 13:57:53 -04:00
parent a4178e4c18
commit e48790de77
2 changed files with 6 additions and 33 deletions
+4 -32
View File
@@ -20,11 +20,7 @@ import java.io.*;
@SuppressWarnings("unchecked")
public class JsonIO{
private static final CustomJson jsonBase = new CustomJson();
public static final Json json = new Json(){
{ apply(this); }
@Override
public void writeValue(Object value, Class knownType, Class elementType){
if(value instanceof MappableContent c){
@@ -80,8 +76,9 @@ public class JsonIO{
return json.fromJson(type, string.replace("io.anuke.", ""));
}
public static <T> T read(Class<T> type, T base, String string){
return jsonBase.fromBaseJson(type, base, string.replace("io.anuke.", ""));
public static <T> T read(T base, String string){
json.readFields(base, new JsonReader().parse(string.replace("io.anuke.", "")));
return base;
}
public static String print(String in){
@@ -90,10 +87,9 @@ public class JsonIO{
public static void classTag(String tag, Class<?> type){
json.addClassTag(tag, type);
jsonBase.addClassTag(tag, type);
}
static void apply(Json json){
static{
json.setElementType(Rules.class, "spawns", SpawnGroup.class);
json.setElementType(Rules.class, "loadout", ItemStack.class);
@@ -356,28 +352,4 @@ public class JsonIO{
json.addClassTag(Strings.camelize(i.getClass().getSimpleName().replace("Filter", "")), i.getClass());
}
}
static class CustomJson extends Json{
private Object baseObject;
{ apply(this); }
@Override
public <T> T fromJson(Class<T> type, String json){
return fromBaseJson(type, null, json);
}
public <T> T fromBaseJson(Class<T> type, T base, String json){
this.baseObject = base;
return readValue(type, null, new JsonReader().parse(json));
}
@Override
protected Object newInstance(Class type){
if(baseObject == null || baseObject.getClass() != type){
return super.newInstance(type);
}
return baseObject;
}
}
}
+2 -1
View File
@@ -100,7 +100,8 @@ public class Map implements Comparable<Map>, Publishable{
public Rules rules(Rules base){
try{
Rules result = JsonIO.read(Rules.class, base, tags.get("rules", "{}"));
Rules result = JsonIO.read(base, tags.get("rules", "{}"));
//replace the default serpulo env with erekir
if(result.planet == Planets.serpulo && result.hasEnv(Env.scorching)){
result.planet = Planets.erekir;