Solved Deserialize persistentContainer in itemMeta

Discussion in 'Spigot Plugin Development' started by plekz, Mar 14, 2020.

  1. Hi, Im trying to deserialize an itemstacks with itemMeta and the persistent data. I've been searching around and found mulitple methods to use, but none of them would let me access the stored data. Because then it gives me this error:
    Code (Text):
           at Source) [?:?]
    Caused by: java.lang.IllegalArgumentException: `The found tag instance cannot store String as it is a NBTTagByte
            at ~[spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.persistence.CraftPersistentDataTypeRegistry.extract( ~[spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.persistence.CraftPersistentDataContainer.get( ~[spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
            at me.gubbestor.glib.utils.ItemUtil.getItemData( ~[?:?]
            at me.gubbestor.glib.button.ButtonEvent.onPlace( ~[?:?]
            at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
            at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
            at$1.execute( ~[spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
            ... 20 more
    It has nothing to do with my library as shown in the error, because i use my my library with those methods in other plugins.

    I found a method to deserialize the itemMeta(I edited it some when trying to access the stored data):
    Code (Text):
        private static ItemStack[] deserializeItemStack(Map<String, Object>[] map) {
            ItemStack[] items = new ItemStack[map.length];
            for(int i = 0; i < items.length; i++) {
                Map<String, Object> itemMap = map[i];
                if(itemMap.size() == 0) {
                    items[i] = null;
                }else {
                    try {
                        if(itemMap.containsKey("meta")) {
                            Map<String, Object> itemMetaMap = new HashMap<>(
                                    (Map<String, Object>) itemMap.get("meta"));
                            ItemStack item = ItemStack.deserialize(itemMap);
                            ItemMeta meta = (ItemMeta) ConfigurationSerialization.deserializeObject(itemMetaMap, ConfigurationSerialization.getClassByAlias("ItemMeta"));
                            items[i] = item;
                        }else {
                            items[i] = ItemStack.deserialize(itemMap);
                    }catch(Exception e) {
                        items[i] = null;
            return items;
    I know the data is in the map because i managed to print it in a yml file
    but i dont know why i cant access it.