NBT tag Help?

Discussion in 'Plugin Development' started by bobnixon1, Dec 12, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    bobnixon1

    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?
     
  2. Offline

    Gravity

    Moved to the correct section
     
  3. Offline

    fireblast709

    You would need to use Craftbukkit (as library, instead of bukkit)
    Code:java
    1. CraftItemStack cis = new CraftItemStack(originalItemStack);
    2. cis.getHandle().c("new name");
    3. // then set the item to cis
     
    chasechocolate likes this.
  4. Offline

    bobnixon1

    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.
     
  5. Offline

    fireblast709

    read the first line: you need Craftbukkit instead of Bukkit
     
  6. Offline

    bobnixon1

    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
     
  7. Offline

    fireblast709

    the library would mean: instead of using the Bukkit jar in your projects, use Craftbukkit.jar (the server file)
     
  8. Offline

    bobnixon1

  9. Offline

    fireblast709

    then what is the problem?
     
  10. Offline

    bobnixon1

    well, i don't know how to edit NBT tags
     
  11. Offline

    fireblast709

    you don't have to. My code should be enough :3 (which internally edits the NBT tags, if you want to know)
     
  12. Offline

    bobnixon1

    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
     
  13. Offline

    Jogy34

    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.
     
  14. Offline

    bobnixon1

    thanks i got that but i don't know how to edit NBT tags. could you tell me?
     
  15. Offline

    Tirelessly

     
  16. Offline

    gomeow

    You don't need to edit them to change what their name is. The c(String) method handles it for you
     
  17. Offline

    bobnixon1

    I have made the itemstack but when i do cis.getHandle().c("itemname"); it says identifier expected after getHandle() token. Help?
     
  18. Offline

    fireblast709

    Since the latest Bukkit dev build, this is no longer neccesary. Now you can use ItemMeta, which is implemented by Bukkit
    Code:java
    1. ItemStack is = new ItemStack(Material.GOLD_SWORD, 1);
    2. ItemMeta im = is.getItemMeta();
    3. im.setDisplayName("Demon Banisher");
    4. ArrayList<String> lore = new ArrayList<String>();
    5. lore.add("Banishes demons");
    6. lore.add("And cooks your pork");
    7. im.setLore(lore);
    8. is.setItemMeta(im);
     
  19. Offline

    bobnixon1

    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.
     
    Last edited by a moderator: May 30, 2016
  20. Offline

    SnowGears

    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...
     
  21. Offline

    fireblast709

    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)
     
  22. Offline

    SnowGears

    I have the latest dev build and it still gives the error. Does it work for you?
     
  23. Offline

    tommycake50

    You can do that now :D?
     
  24. Offline

    fireblast709

    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
     
  25. Offline

    SnowGears

    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.
     
  26. Offline

    bobnixon1

    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?
     
Thread Status:
Not open for further replies.

Share This Page