Add missing ItemStack serializer

This commit is contained in:
libraryaddict 2017-07-23 23:56:45 +12:00
parent 926aea53f6
commit b817aebc02
2 changed files with 29 additions and 0 deletions

View File

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

View File

@ -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<ItemStack>, JsonDeserializer<ItemStack> {
@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<String, Object>) context.deserialize(json, HashMap.class));
}
}