Solved [1.17] NBTTag doesn't save when converting NMS ItemStack to Bukkit ItemStack

Discussion in 'Spigot Plugin Development' started by LeonidM, Jul 17, 2021.

  1. Hi! I'm using Spigot 1.17 and when I'm trying to convert skull represented as NMS ItemStack to Bukkit ItemStack, it just doesn't save any information, because of it I get a player head without any skin at it.

    Here is my code:

    Code (Java):
    public static ItemStack setSkullOwner(ItemStack itemStack, String id, String textureValue) {
   nmsStack = CraftItemStack.asNMSCopy(itemStack);

            NBTTagCompound compound = nmsStack.getTag() == null ? new NBTTagCompound() : nmsStack.getTag();

            NBTTagCompound skullOwner = new NBTTagCompound();
            skullOwner.setString("Id", id);
            NBTTagCompound properties = new NBTTagCompound();
            NBTTagList textures = new NBTTagList();
            NBTTagCompound value = new NBTTagCompound();
            value.setString("Value", textureValue);
            properties.set("textures", textures);
            skullOwner.set("Properties", properties);

            compound.set("SkullOwner", skullOwner);

            return CraftItemStack.asBukkitCopy(nmsStack);
    And here is the code in another method:
    Code (Java):
    ItemStack skull = Main.setSkullOwner(new ItemStack(Material.PLAYER_HEAD), UUID.randomUUID().toString(), configData.getString(key));
         nms = CraftItemStack.asNMSCopy(skull);
    And here's the output:
    Code (Text):
    [01:49:52] [Server thread/INFO]: {SkullOwner:{Id:"f9f666c4-33b9-11eb-adc1-0242ac120002",Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjcyZDFiZTQ4OGQyNjdlY2JlY2Y3ZmJjMzE0MzkwNjM2ZTk0MmI2NDYwNjI4YjAyMTA0YTgzODE4NGI3ZTczNyJ9fX0="}]}}}
    [01:49:52] [Server thread/INFO]: null
    I know that there is no NMS at 1.17 but I didn't find any information about NBTTags and something like this, so I will be the thankful anyone who will help me.
    #1 LeonidM, Jul 17, 2021
    Last edited: Jul 17, 2021
  2. What if you use CraftItemStack#asCraftMirror instead of CraftItemStack#asBukkitCopy? I vaguely remember that asCraftMirror just wraps the nms-ItemStack into a CraftItemStack (which extends org.bukkit.inventory.ItemStack), while asBukkitCopy just copies properties as recognised by Bukkit onto a new bukkit-ItemStack.
  3. Thanks a lot, it works!
    • Friendly Friendly x 1
  4. You can mark the thread as [Solved] then.