[SPIGOT-4577] ItemStack / YamlConfiguration getItemStack converts string to integer Created: 13/Jan/19  Updated: 13/Jan/19  Resolved: 13/Jan/19

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Michael Bolland Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows 10

java version "1.8.0_191"


Version: CraftBukkit version git-Spigot-f56e2e7-98b862a (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

getCustomTagContainer().setCustomTag(key1, ItemTagType.STRING, "1"); saving to yaml, restoring to itemstack and trying to getTag will return false for hasCustomTag(key1 , ItemTagType.STRING)) as the values have made their way into the restored stack as INTEGER rather than STRING

Crude Example / Output:
 

public boolean TestItemStackTagsDiffer()
     {
         ItemStack itemStack = new ItemStack(Material.IRON_SWORD);
         NamespacedKey key1 = new NamespacedKey(Bukkit.getPluginManager().getPlugin("Solinia3Core"), "testtag1");
         NamespacedKey key2 = new NamespacedKey(Bukkit.getPluginManager().getPlugin("Solinia3Core"), "testtag2");
        
         ItemMeta meta = itemStack.getItemMeta();
         meta.getCustomTagContainer().setCustomTag(key1, ItemTagType.STRING, "1");
         meta.getCustomTagContainer().setCustomTag(key2, ItemTagType.STRING, "2");
         itemStack.setItemMeta(meta);
  
         System.out.println("tagtag1: " + itemStack.getItemMeta().getCustomTagContainer().hasCustomTag(key1 , ItemTagType.STRING));
         System.out.println("tagtag2: " + itemStack.getItemMeta().getCustomTagContainer().hasCustomTag(key2 , ItemTagType.STRING));
        
         YamlConfiguration config = new YamlConfiguration();
         config.set("serialized-item-stack", itemStack);
         String itemStackAsString = config.saveToString();
        
         try
{             config.loadFromString(itemStackAsString);         }
catch (InvalidConfigurationException e)
{             // TODO Auto-generated catch block             e.printStackTrace();             return true;         }
       
         System.out.println("Old Item Stack: ");
         System.out.println(config.saveToString());
        
         ItemStack restoredItem = config.getItemStack("serialized-item-stack");
        
         config.set("serialized-item-stack", restoredItem);
         System.out.println("New Item Stack: ");
         System.out.println(config.saveToString());
        
         System.out.println("tagtag1: " + restoredItem.getItemMeta().getCustomTagContainer().hasCustomTag(key1 , ItemTagType.STRING));
         System.out.println("tagtag2: " + restoredItem.getItemMeta().getCustomTagContainer().hasCustomTag(key2 , ItemTagType.STRING));
        
         boolean anyWrong = false;
        
         if(!restoredItem.getItemMeta().getCustomTagContainer().hasCustomTag(key1 , ItemTagType.STRING))
             anyWrong = true;
        
         if(!restoredItem.getItemMeta().getCustomTagContainer().hasCustomTag(key2, ItemTagType.STRING))
             anyWrong = true;
        
         return anyWrong;
            
     }

 

 

[11:53:14 INFO]: tagtag1: true
[11:53:14 INFO]: tagtag2: true
[11:53:14 INFO]: Old Item Stack:
[11:53:14 INFO]: serialized-item-stack:
  ==: org.bukkit.inventory.ItemStack
  v: 1631
  type: IRON_SWORD
  meta:
    ==: ItemMeta
    meta-type: UNSPECIFIC
    PublicBukkitValues:
      solinia3core:testtag2: '2'
      solinia3core:testtag1: '1'
 
[11:53:14 INFO]: New Item Stack:
[11:53:14 INFO]: serialized-item-stack:
  ==: org.bukkit.inventory.ItemStack
  v: 1631
  type: IRON_SWORD
  meta:
    ==: ItemMeta
    meta-type: UNSPECIFIC
    PublicBukkitValues:
      solinia3core:testtag2: '2'
      solinia3core:testtag1: '1'
 
[11:53:14 INFO]: tagtag1: false
[11:53:14 INFO]: tagtag2: false



 Comments   
Comment by Bjarne Koll [ 13/Jan/19 ]

Added tests and fix: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/pull-requests/520/overview

Comment by Bjarne Koll [ 13/Jan/19 ]

True, due to Mojang simply not caring about assigning the type identifier i to integers. I'll open a pr 

Generated at Fri Dec 19 04:09:41 UTC 2025 using Jira 10.3.15#10030015-sha1:909cc43d292ca09e774c1a243d9819be3f2628cd.