[SPIGOT-7636] ItemStack#setItemMeta(null) issue Created: 25/Apr/24 Updated: 25/Dec/24 Resolved: 25/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: | md_5 |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
| Version: | CraftBukkit version 4117-Spigot-b698b49-ebb50e1 (MC: 1.20.5) |
| Plugin: | just my test plugin |
| Guidelines Read: | Yes |
| Description |
|
Ok this one is an odd one. I don't even really know what is going on here, so I will try my best to explain this. Long story short, it appears attempting to clear the item meta of an ItemStack that was gotten from the player's hand, locks the meta in, it can't be cleared. Scenario One:
Scenario Two:
Ive tested this on both 1.20.4 (doesn't happen) and 1.20.5 (happens) I'll include a jar for testing, here is the code snippet: if (args.length > 0 && args[0].equals("one")) { ItemStack itemStack = new ItemStack(Material.DIAMOND_AXE); itemStack.addEnchantment(Enchantment.SHARPNESS, 5); player.getInventory().addItem(itemStack); Bukkit.getLogger().info("MetaBefore: " + itemStack.getItemMeta()); itemStack.setItemMeta(null); Bukkit.getLogger().info("MetaAfter: " + itemStack.getItemMeta()); } else if (args.length > 0 && args[0].equals("two")) { ItemStack itemStack = player.getInventory().getItemInMainHand(); Bukkit.getLogger().info("MetaBefore: " + itemStack.getItemMeta()); itemStack.setItemMeta(null); Bukkit.getLogger().info("MetaAfter: " + itemStack.getItemMeta()); } Steps to replicate with included jar.
|
| Comments |
| Comment by Shane Bee [ 25/Apr/24 ] |
|
Thanks. I was writing code for my Skript addon, and I spent about 5 hours screaming with like 10+ debug messages, not understanding what was going on. Took me a good amount of time to narrow it down to the item meta not resetting (or clearing of any sort). Then I had to test again in a real plugin environment so I could properly report it. I dug around in CB code and just couldn't figure it out, so thanks again for fixing it. |
| Comment by md_5 [ 25/Apr/24 ] |
|
Good pickup and not so easy fix, fingers crossed - thanks! |