From 3582d1ffeded682acecadfa1a0a604b1473b8f14 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 25 Feb 2021 04:39:30 +1300 Subject: [PATCH] Fix a weird issue where json deserializing didn't work out of the blue --- .../utilities/json/SerializerFlagWatcher.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java index 12c30c8c..e437faaf 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java @@ -21,8 +21,7 @@ import java.util.Optional; /** * Created by libraryaddict on 1/06/2017. */ -public class SerializerFlagWatcher - implements JsonDeserializer, JsonSerializer, InstanceCreator { +public class SerializerFlagWatcher implements JsonDeserializer, JsonSerializer, InstanceCreator { private Gson gson; public SerializerFlagWatcher(Gson gson) { @@ -30,11 +29,9 @@ public class SerializerFlagWatcher } @Override - public FlagWatcher deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { + public FlagWatcher deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try { - FlagWatcher watcher = - (FlagWatcher) gson.fromJson(json, Class.forName(((JsonObject) json).get("flagType").getAsString())); + FlagWatcher watcher = (FlagWatcher) gson.fromJson(json, Class.forName(((JsonObject) json).get("flagType").getAsString())); DisguiseType entity = DisguiseType.valueOf(((JsonObject) json).get("entityType").getAsString()); @@ -75,8 +72,7 @@ public class SerializerFlagWatcher } } else if (entry.getValue() instanceof String) { if (index.getDefault() instanceof WrappedParticle) { - entry.setValue(((ParamInfoParticle) ParamInfoManager.getParamInfo(WrappedParticle.class)) - .fromString((String) entry.getValue())); + entry.setValue(((ParamInfoParticle) ParamInfoManager.getParamInfo(WrappedParticle.class)).fromString((String) entry.getValue())); } } else if (entry.getValue() instanceof LinkedTreeMap) { // If it's deserialized incorrectly as a map // If the default value is not VillagerData @@ -103,9 +99,7 @@ public class SerializerFlagWatcher if (((LinkedTreeMap) entry.getValue()).isEmpty()) { value = Optional.empty(); } else { - value = Optional.of( - gson.fromJson(gson.toJson(((LinkedTreeMap) entry.getValue()).get("value")), - val)); + value = Optional.of(gson.fromJson(gson.toJson(((LinkedTreeMap) entry.getValue()).get("value")), val)); } entry.setValue(value); @@ -131,7 +125,7 @@ public class SerializerFlagWatcher @Override public FlagWatcher createInstance(Type type) { try { - return (FlagWatcher) type.getClass().getConstructor(Disguise.class).newInstance(null); + return (FlagWatcher) ((Class) type).getConstructor(Disguise.class).newInstance(new Object[]{null}); } catch (Exception e) { e.printStackTrace(); }