-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Minor
-
None
-
Affects Version/s: None
-
None
-
CraftBukkit version 4117-Spigot-b698b49-ebb50e1 (MC: 1.20.5)
-
just my test plugin
-
Yes
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:
- create a new ItemStack and enchant it with sharpness 5
- send the ItemMeta of that stack (it will send that the sharpness is there)
- clear the meta via `ItemStack#setItemMeta(null)`
- Send the ItemMeta of that stack (it will not have the enchantment)
So that is a yay!
Scenario Two:
- Set an ItemStack var to `player.getInventory().getItemInMainHand()`
- send the ItemMeta of that stack (it will send that the sharpness is there)
- clear the meta via `ItemStack#setItemMeta(null)`
- send the ItemMeta of that stack (it will send that the sharpness is there... that shouldn't happen.)
Ive tested this on both 1.20.4 (doesn't happen) and 1.20.5 (happens)
This is odd behaviour.
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.
- Clear your inventory
- Run command `/test one`
- This will give you an item (we shall use this later)
- You should see the following output in console:
[22:15:22] [Server thread/INFO]: YourNameHere issued server command: /test one [22:15:22] [Server thread/INFO]: MetaBefore: UNSPECIFIC_META:{meta-type=UNSPECIFIC, enchants={DAMAGE_ALL=5}} [22:15:22] [Server thread/INFO]: MetaAfter: UNSPECIFIC_META:{meta-type=UNSPECIFIC}
As you can see, the meta is updated/cleared as we would expect.
- Now make sure that item we gave you is in your main hand
- Run the command `/test two`
- You should see the following output in console:
[22:22:17] [Server thread/INFO]: YourNameHere issued server command: /test two [22:22:17] [Server thread/INFO]: MetaBefore: UNSPECIFIC_META:{meta-type=UNSPECIFIC, enchants={DAMAGE_ALL=5}} [22:22:17] [Server thread/INFO]: MetaAfter: UNSPECIFIC_META:{meta-type=UNSPECIFIC, enchants={DAMAGE_ALL=5}}
As you can see here, the meta was not cleared. It's like its being locked in.