[SPIGOT-4577] ItemStack / YamlConfiguration getItemStack converts string to integer Created: 13/Jan/19 Updated: 13/Jan/19 Resolved: 13/Jan/19 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Michael Bolland | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Windows 10 java version "1.8.0_191" |
||
| Version: | CraftBukkit version git-Spigot-f56e2e7-98b862a (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT) |
| Guidelines Read: | Yes |
| Description |
|
getCustomTagContainer().setCustomTag(key1, ItemTagType.STRING, "1"); saving to yaml, restoring to itemstack and trying to getTag will return false for hasCustomTag(key1 , ItemTagType.STRING)) as the values have made their way into the restored stack as INTEGER rather than STRING Crude Example / Output: public boolean TestItemStackTagsDiffer() { ItemStack itemStack = new ItemStack(Material.IRON_SWORD); NamespacedKey key1 = new NamespacedKey(Bukkit.getPluginManager().getPlugin("Solinia3Core"), "testtag1"); NamespacedKey key2 = new NamespacedKey(Bukkit.getPluginManager().getPlugin("Solinia3Core"), "testtag2"); ItemMeta meta = itemStack.getItemMeta(); meta.getCustomTagContainer().setCustomTag(key1, ItemTagType.STRING, "1"); meta.getCustomTagContainer().setCustomTag(key2, ItemTagType.STRING, "2"); itemStack.setItemMeta(meta); System.out.println("tagtag1: " + itemStack.getItemMeta().getCustomTagContainer().hasCustomTag(key1 , ItemTagType.STRING)); System.out.println("tagtag2: " + itemStack.getItemMeta().getCustomTagContainer().hasCustomTag(key2 , ItemTagType.STRING)); YamlConfiguration config = new YamlConfiguration(); config.set("serialized-item-stack", itemStack); String itemStackAsString = config.saveToString(); try { config.loadFromString(itemStackAsString); } catch (InvalidConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); return true; } System.out.println("Old Item Stack: "); System.out.println(config.saveToString()); ItemStack restoredItem = config.getItemStack("serialized-item-stack"); config.set("serialized-item-stack", restoredItem); System.out.println("New Item Stack: "); System.out.println(config.saveToString()); System.out.println("tagtag1: " + restoredItem.getItemMeta().getCustomTagContainer().hasCustomTag(key1 , ItemTagType.STRING)); System.out.println("tagtag2: " + restoredItem.getItemMeta().getCustomTagContainer().hasCustomTag(key2 , ItemTagType.STRING)); boolean anyWrong = false; if(!restoredItem.getItemMeta().getCustomTagContainer().hasCustomTag(key1 , ItemTagType.STRING)) anyWrong = true; if(!restoredItem.getItemMeta().getCustomTagContainer().hasCustomTag(key2, ItemTagType.STRING)) anyWrong = true; return anyWrong; }
[11:53:14 INFO]: tagtag1: true |
| Comments |
| Comment by Bjarne Koll [ 13/Jan/19 ] |
|
Added tests and fix: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/pull-requests/520/overview |
| Comment by Bjarne Koll [ 13/Jan/19 ] |
|
True, due to Mojang simply not caring about assigning the type identifier i to integers. I'll open a pr |