@Cat 700 It's been a while since i've used it but i think something like this works: Code:Java // This is the Bukkit ItemStack (org.bukkit.inventory.ItemStack)ItemStack item = new ItemStack(Material.DIAMOND); // Just an example item// This is the NMS ItemStacknet.minecraft.server./*version*/.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);// Get the NBT tagNBTTagCompound tag = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();// I don't remember this method, just look through the methods and see which one is kinda like thistag.setString("key", "value");// Set the NBT tag to the modified versionnmsItem.setTag(tag);// Get the Bukkit ItemStack after modificationitem = CraftItemStack.asBukkitCopy(nmsItem);
I am sorry I am not the best with plugin code so where would I put the nbt? also how would I edit the nbt I feel like it is in your code but I don't understand most of it other than the itemstack I don't do a lot of plugin coding
@Cat 700 You set it using the 'setString(key, value)' but as i said i don't remember if that's the exact method, just look at the possible methods for that. I commented the code to briefly explain it.
@KarimAKL ok I understand but some of that code has errors it might be because I am using 1.14.2 but IDK
@KarimAKL the errors that I am getting are from the nmsItem.setTag(tag); and tag.setString("key", "value"); the nmsitem one is saying identifier expected and then the tag.setstring is saying quite a few things also my code is Code:Java package me.cat700.MythicalArmorWands; import org.bukkit.Material;import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;import org.bukkit.inventory.ItemStack; import net.minecraft.server.v1_14_R1.NBTTagCompound; public class MythicalArmorWands { // This is the Bukkit ItemStack (org.bukkit.inventory.ItemStack) ItemStack item = new ItemStack(Material.DIAMOND); // Just an example item // This is the NMS ItemStack net.minecraft.server.v1_14_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); // Get the NBT tag NBTTagCompound tag = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound(); // I don't remember this method, just look through the methods and see which one is kinda like this tag.setString("key", "value"); // Set the NBT tag to the modified version nmsItem.setTag(tag); // Get the Bukkit ItemStack after modification item = CraftItemStack.asBukkitCopy(nmsItem);} I found this forum with this code Code:java public NBTTagList getLore(ItemStack i){net.minecraft.server.ItemStack nms = ((CraftItemStack)i).getHandle();NBTTagCompound tag = nms.getTag()if (!tag.hasKey("display")){return new NBTTagList();}NBTTagCompound display = (NBTTagCompound)tag.get("display");NBTTagList lore = display.getList("Lore");if (lore == null){// returns empty listreturn new NBTTagList();}return lore;}public void setLore(String lore, ItemStack i){net.minecraft.server.ItemStack nms = ((CraftItemStack)i).getHandle();NBTTagCompound tag = nms.getTag()if (!tag.hasKey("display")){this.addDisplay();}NBTTagCompound display = this.getDisplay();NBTTagList l = new NBTTagList();// Added multiline lore support// Splits the linesString[] loreLines = lore.split("\n");// Add each linefor(String line : loreLines){l.add(new NBTTagString("", line));}// Set the loredisplay.set("Lore", l);} but I do not know how I would use this for what I want @KarimAKL I also found this forum but it doesn't say how to test if it has a nbt tag EDIT by Moderator: merged posts, please use the edit button instead of double posting.
@KarimAKL I have tried many things but I can't find much I tried to do code in this forum but that didn't work I tried replacing the tag.setstring with if(tag.hasKey) but that doesn't work IDK