ItemStack / YamlConfiguration getItemStack converts string to integer

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None
    • Environment:

      Windows 10

      java version "1.8.0_191"

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

      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

            Assignee:
            Unassigned
            Reporter:
            Michael Bolland
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: