So I am making a plugin and i want to rename my items and set their lore. I have looked on NBT tags and changing them but I don't quite understand how they work. Using the code others have made, I cant make an Itemstack that has a item so when I use inv.setItem(0, ITEM); I cant have ITEM already be renamed. Can Someone please explain how this whole NBT tags thingy works and How I can directly rename an Itemstack?
You would need to use Craftbukkit (as library, instead of bukkit) Code:java CraftItemStack cis = new CraftItemStack(originalItemStack);cis.getHandle().c("new name");// then set the item to cis
umm this doesn't work . I can make my ItemStack into a CraftItemStack but getHandler() deosn't seem to be a thing you can do with cis.
sorry, but im new to this and i dont know whatt a craftbukkit library is I know what CraftItemStack is but I dont know how to edit NBT tags either
the library would mean: instead of using the Bukkit jar in your projects, use Craftbukkit.jar (the server file)
you don't have to. My code should be enough :3 (which internally edits the NBT tags, if you want to know)
Your code desn't seem to work. the getHandle() thingy does not work. if the bukkit libray is called craftbukkit than i am not using the craftbukkit library
What he means by that is the actual .jar file you should be importing is the one that you use to run the actual server. You can find it here: http://dl.bukkit.org/downloads/craftbukkit/ The newest Beta build works fine for NBTTags.
I have made the itemstack but when i do cis.getHandle().c("itemname"); it says identifier expected after getHandle() token. Help?
Since the latest Bukkit dev build, this is no longer neccesary. Now you can use ItemMeta, which is implemented by Bukkit Code:java ItemStack is = new ItemStack(Material.GOLD_SWORD, 1);ItemMeta im = is.getItemMeta();im.setDisplayName("Demon Banisher");ArrayList<String> lore = new ArrayList<String>();lore.add("Banishes demons");lore.add("And cooks your pork");im.setLore(lore);is.setItemMeta(im);
i tried im.setDisplayName("myname"); but it is not working. the "." next to im has an error saying syntax error on token(s) misplaced construct(s) and "myname" has an error saying syntax error on "myname", delete this token. do you know how to use the new ItemMeta in the new dev buil dof bukkit? it dens't seem to work for me EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Im trying this with the newest dev build and getting a "No Such Method Error" for is.getItemMeta(); It compiles fine but on starting the server it spams with it...
Tooner101 you probably should get the latest CB for it to work bobnixon1 getItemMeta() returns a copy of the ItemMeta, so after you modified it, call setItemMeta(modified ItemMeta)
tommycake50 yes Tooner101 bobnixon1 I could compile perfectly fine with the latest CB dev build, so it is added in the latest CB. Updating your server-used Craftbukkit should solve the problem
Ohhhh.... That must be it. I forgot to update the craftbukkit the server is running on. Thanks! I will try that when I get home.
i did have that, buit i am doing all of this in a sperate class. do i need to have this code in something or add something in my main plugin class?