From 3b3de8d0ee16fa90fc29278c45d5f09e384485a4 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 21 Dec 2019 19:12:22 +1300 Subject: [PATCH] Catch CraftItemStack when de/serializing, fixes #414 --- .../disguise/utilities/DisguiseUtilities.java | 8 +++++--- .../utilities/json/SerializerFlagWatcher.java | 12 ++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index c4098709..b749b9f4 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -811,14 +811,16 @@ public class DisguiseUtilities { } GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(MetaIndex.class, new SerializerMetaIndex()); gsonBuilder.registerTypeAdapter(WrappedGameProfile.class, new SerializerGameProfile()); gsonBuilder.registerTypeAdapter(WrappedBlockData.class, new SerializerWrappedBlockData()); - gsonBuilder.registerTypeAdapter(Disguise.class, new SerializerDisguise()); - gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerFlagWatcher()); gsonBuilder.registerTypeAdapter(WrappedChatComponent.class, new SerializerChatComponent()); gsonBuilder.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()); - gsonBuilder.registerTypeAdapter(ItemStack.class, new SerializerItemStack()); + gsonBuilder.registerTypeHierarchyAdapter(ItemStack.class, new SerializerItemStack()); + + gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerFlagWatcher(gsonBuilder.create())); + gsonBuilder.registerTypeAdapter(Disguise.class, new SerializerDisguise()); gson = gsonBuilder.create(); 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 347399b2..cf52bd38 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java @@ -27,16 +27,8 @@ public class SerializerFlagWatcher implements JsonDeserializer, Jso InstanceCreator { private Gson gson; - public SerializerFlagWatcher() { - GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.registerTypeAdapter(MetaIndex.class, new SerializerMetaIndex()); - gsonBuilder.registerTypeAdapter(WrappedGameProfile.class, new SerializerGameProfile()); - gsonBuilder.registerTypeAdapter(WrappedBlockData.class, new SerializerWrappedBlockData()); - gsonBuilder.registerTypeAdapter(WrappedChatComponent.class, new SerializerChatComponent()); - gsonBuilder.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()); - gsonBuilder.registerTypeAdapter(ItemStack.class, new SerializerItemStack()); - - gson = gsonBuilder.create(); + public SerializerFlagWatcher(Gson gson) { + this.gson = gson; } @Override