Added chat serializing which should clear a rare issue

This commit is contained in:
libraryaddict 2018-12-13 11:28:02 +13:00
parent 0393613a67
commit 9e7f332788
3 changed files with 30 additions and 0 deletions

View File

@ -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());

View File

@ -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<WrappedChatComponent>,
JsonSerializer<WrappedChatComponent> {
@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());
}
}

View File

@ -82,6 +82,7 @@ public class SerializerFlagWatcher implements JsonDeserializer<FlagWatcher>, Jso
JsonObject obj = (JsonObject) context.serialize(src);
obj.addProperty("flagType", src.getClass().getName());
try {
Method method = FlagWatcher.class.getDeclaredMethod("getDisguise");
method.setAccessible(true);