[SPIGOT-6467] InventoryClickEvent does not always write meta Created: 23/May/21 Updated: 23/May/21 Resolved: 23/May/21 |
|
Status: | Closed |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Major |
Reporter: | Daniel | Assignee: | Unassigned |
Resolution: | Invalid | Votes: | 0 |
Labels: | 1.16.5, API, spigot |
Attachments: |
![]() |
Version: | This server is running CraftBukkit version 3083-Spigot-9fb885e-9c7acb6 (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT) |
Guidelines Read: | Yes |
Description |
When using InventoryClickEvent to modify item meta, it writes it back only if moving between different inventories. Example: Move item from player inventory to a chest, data is being written. Move item from player inventory to another slot, data is not written. Sample code: @EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClickEvent(InventoryClickEvent event) { ItemStack item = event.getCurrentItem(); if(item == null) { return; } ItemMeta meta = item.getItemMeta(); if(meta == null) return; PersistentDataContainer dataContainer = meta.getPersistentDataContainer(); NamespacedKey key = NamespacedKey.fromString("testkey"); if(key == null) return; dataContainer.set(key, PersistentDataType.LONG, 123L); } To check for the data, get the item in hand and use
Reproducing with attached plugin: Get any item, try to move it inside own inventory, it will print in chat "Read: null", data was not written, as reading it returned null. If you move it into another inventory and try to move it again it will print "Read: 1", data was written, as reading it returned the data. |
Comments |
Comment by Black Hole [ 23/May/21 ] |
ItemMeta is actually a snapshot copy of the itemstack data. You have to apply it back to the itemstack using ItemStack.setItemMeta() |