[SPIGOT-7644] ItemMeta#getAsString = wrong output Created: 27/Apr/24  Updated: 25/Dec/24  Resolved: 27/Apr/24

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

Type: Bug Priority: Minor
Reporter: Shane Bee Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None

Attachments: File Test-1.0-SNAPSHOT.jar    
Version: CraftBukkit version 4129-Spigot-b698b49-7ddb482 (MC: 1.20.5)
Plugin: only test plugin
Guidelines Read: Yes

 Description   

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"]}'}}


 Comments   
Comment by Shane Bee [ 27/Apr/24 ]

Huzzah!!!
Thank you!

Comment by md_5 [ 27/Apr/24 ]

New output:

{"minecraft:custom_name":'{"extra":["Mr Swordy Sword"],"text":""}',"minecraft:enchantments":{levels:{"minecraft:sharpness":3,"minecraft:unbreaking":3}},"minecraft:lore":['{"extra":["Super Sharp"],"text":""}','{"extra":["Be Careful"],"text":""}']}
Generated at Sat Dec 13 20:46:19 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.