From b817aebc02aed0d059641f1f77f4ce04246ac4bc Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 23 Jul 2017 23:56:45 +1200 Subject: [PATCH] Add missing ItemStack serializer --- .../disguise/utilities/DisguiseUtilities.java | 1 + .../utilities/json/SerializerItemStack.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/me/libraryaddict/disguise/utilities/json/SerializerItemStack.java diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index be2661c7..4319312b 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -834,6 +834,7 @@ public class DisguiseUtilities { gsonBuilder.registerTypeAdapter(Disguise.class, new SerializerDisguise()); gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerFlagWatcher()); gsonBuilder.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()); + gsonBuilder.registerTypeAdapter(ItemStack.class, new SerializerItemStack()); gson = gsonBuilder.create(); diff --git a/src/me/libraryaddict/disguise/utilities/json/SerializerItemStack.java b/src/me/libraryaddict/disguise/utilities/json/SerializerItemStack.java new file mode 100644 index 00000000..84a32831 --- /dev/null +++ b/src/me/libraryaddict/disguise/utilities/json/SerializerItemStack.java @@ -0,0 +1,28 @@ +package me.libraryaddict.disguise.utilities.json; + +import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.google.gson.*; +import com.mojang.authlib.GameProfile; +import org.bukkit.inventory.ItemStack; + +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +/** + * Created by libraryaddict on 1/06/2017. + */ +public class SerializerItemStack implements JsonSerializer, JsonDeserializer { + + @Override + public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) { + return context.serialize(src.serialize()); + } + + @Override + public ItemStack deserialize(JsonElement json, Type typeOfT, + JsonDeserializationContext context) throws JsonParseException { + return ItemStack.deserialize((Map) context.deserialize(json, HashMap.class)); + } +}