Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7644

ItemMeta#getAsString = wrong output

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • CraftBukkit version 4129-Spigot-b698b49-7ddb482 (MC: 1.20.5)
    • only test plugin
    • Yes

      I noticed when using the output of ItemMeta#getAsString() its not returning a true sNBT output as it did in previous versions.

      Example output of an item:

       {minecraft:custom_name=>empty[siblings=[literal{Mr Swordy Sword}]], minecraft:lore=>ItemLore[lines=[empty[siblings=[literal{Super Sharp}]], empty[siblings=[literal{Be Careful}]]], styledLines=[empty[style={color=dark_purple,italic}, siblings=[literal{Super Sharp}]], empty[style={color=dark_purple,italic}, siblings=[literal{Be Careful}]]]], minecraft:enchantments=>ItemEnchantments{enchantments={Reference{ResourceKey[minecraft:enchantment / minecraft:unbreaking]=net.minecraft.world.item.enchantment.EnchantmentDurability@17cd6c05}=>3, Reference{ResourceKey[minecraft:enchantment / minecraft:sharpness]=net.minecraft.world.item.enchantment.EnchantmentWeaponDamage@2072b9ba}=>3}, showInTooltip=true}}
      

      Including a test jar, steps to replicate:

      • run command "/test" (output will be in console)

      Code from command/test plugin:

      ItemStack itemStack = new ItemStack(Material.DIAMOND_SWORD);
      ItemMeta itemMeta = itemStack.getItemMeta();
      assert itemMeta != null;
      itemMeta.addEnchant(Enchantment.SHARPNESS, 3, true);
      itemMeta.addEnchant(Enchantment.UNBREAKING, 3, true);
      itemMeta.setDisplayName("Mr Swordy Sword");
      itemMeta.setLore(Arrays.asList("Super Sharp", "Be Careful"));
      
      Bukkit.getLogger().info("Meta as String: " + itemMeta.getAsString());
      

      Output on 1.20.4:

      {Enchantments:[{id:"minecraft:sharpness",lvl:3s},{id:"minecraft:unbreaking",lvl:3s}],display:{Lore:['{"text":"","extra":["Super Sharp"]}','{"text":"","extra":["Be Careful"]}'],Name:'{"text":"","extra":["Mr Swordy Sword"]}'}}
      

            Unassigned Unassigned
            ShaneBee Shane Bee
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: