diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 681da100..1cfe8b90 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -861,6 +861,7 @@ public class DisguiseUtilities { gsonBuilder.registerTypeAdapter(WrappedBlockData.class, new SerializerWrappedBlockData()); gsonBuilder.registerTypeAdapter(Disguise.class, new SerializerDisguise()); gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerFlagWatcher()); + gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerChatComponent()); gsonBuilder.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()); gsonBuilder.registerTypeAdapter(ItemStack.class, new SerializerItemStack()); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerChatComponent.java b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerChatComponent.java new file mode 100644 index 00000000..d5e5ffcb --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerChatComponent.java @@ -0,0 +1,28 @@ +package me.libraryaddict.disguise.utilities.json; + +import com.comphenix.protocol.wrappers.WrappedChatComponent; +import com.google.gson.*; + +import java.lang.reflect.Type; + +/** + * Created by libraryaddict on 27/11/2018. + */ +public class SerializerChatComponent implements JsonDeserializer, + JsonSerializer { + + @Override + public WrappedChatComponent deserialize(JsonElement json, Type typeOfT, + JsonDeserializationContext context) throws JsonParseException { + if (json.isJsonPrimitive()) { + return WrappedChatComponent.fromJson(json.getAsString()); + } + + return null; + } + + @Override + public JsonElement serialize(WrappedChatComponent src, Type typeOfSrc, JsonSerializationContext context) { + return context.serialize(src.getJson()); + } +} 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 7fc7d6f7..caac0683 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java @@ -82,6 +82,7 @@ public class SerializerFlagWatcher implements JsonDeserializer, Jso JsonObject obj = (JsonObject) context.serialize(src); obj.addProperty("flagType", src.getClass().getName()); + try { Method method = FlagWatcher.class.getDeclaredMethod("getDisguise"); method.setAccessible(true);