I'm stumped...

Discussion in 'Plugin Development' started by Appljuze, Nov 10, 2012.

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

    Appljuze

    I'm trying to change the name of an item, but I just cant seem to get it right. The closest I've come is getting the server to recognize that it's a custom-named item, but it doesn't actually show the name in the tooltip. Anyone know what's wrong? Here's my code for the command:
    Code:
            if(commandLabel.equalsIgnoreCase("nugget")){
                ItemStack nugget = new ItemStack(Material.GOLD_NUGGET);
                Namer.setName(nugget, "My nuggets");
                PlayerInventory pi = player.getInventory();
                pi.addItem(nugget);
            }
    Also here's a link to the page of the Library that I'm using for it : http://forums.bukkit.org/threads/lib-prettyscarylib.110164/

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  2. Offline

    toothplck1

    Changing the name for the CLIENT will require a CLIENT side mod
     
  3. Offline

    cman1885

    No it won't, it'll require 1.4...
     
    ZeusAllMighty11 likes this.
  4. Offline

    Appljuze

    You can change the name of items with an anvil, so this Library just enables you to do it without an anvil. I'm going to assume you don't know how to do it :(
    Right.
     
  5. Offline

    Jogy34

    This is a method I got from someone for renaming items. I use it in my auto-rename plugin

    Code:
    public ItemStack renameItem(ItemStack is, String newName)
    {
      //Get the nms item stack
      CraftItemStack cis = ((CraftItemStack)is);
      //Gets the NBTTagCompound for the item stack
      NBTTagCompound tag = cis.getHandle().getTag();
      //If the tag doesnt exist, create one.
      if(tag == null)
            {
        cis.getHandle().setTag(new NBTTagCompound());
        tag = cis.getHandle().getTag();
      }
      //Check if the item stacks tag has a sub tag called "display" (im assuming this holds all of the new stuff for the item stack display and lore stuff, such as name and flavor text) If it doesnt have the tag, create one. It will most likely not have the tag if it doesnt have any display information. The server may use this to determine whether or not to color the items nameplate purple or not. But thats just me speculating.
      if(tag.getCompound("display") != null)
            {
        tag.setCompound("display", new NBTTagCompound());
      }
      // Gets the display tag.
      NBTTagCompound display = tag.getCompound("display");
      //Removes the old name
      display.remove("Name");
      //sets the new name
      display.setString("Name", newName);
      //Returns the item stack. Technically it is the same object that you passed into the method, but returning is just for convenience. You need to remove, and readd the item stack to the players inventory for the effects to show up.
      return is;
    }
    
    EDIT: This works without any library
     
  6. Offline

    Appljuze

    Very impressive, I'll try it now :)

    Not to be a bother but could you explain the renameItem part? Eclipse isn't recognizing it. Forgive the noobishness, I'm a beginner at Java.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  7. Offline

    toothplck1

    I'm sorry 1.4 does allow you to rename items as you go, but I had thought you were asking how to get the client to universally recognize all of one type of item as a different name, which isn't the same thing. My bad/
     
  8. Offline

    Appljuze

    All good man! I'm trying to rename all of the gold nuggets that drop to be named "Token". It still functions as a gold nugget but its a little cooler if it's named a token, since that's what it represents on my server.
    Anyway, honest mistake. Don't suppose you understand the code block Jogy34 posted?
     
  9. Offline

    ZeusAllMighty11

    Appljuze

    If you are wishing to modify the name every time it's dropped,
    check the itemdropevent, if the item is goldnugget, change it to your thing
     
  10. Offline

    toothplck1

    I would assume you need to import CraftBukkit in addition to Bukkit to use NBT tags and CraftItemStacks.(I am guessing that you probably had forgotten or not realized that)

    Also just remember that gold nuggets can also be obtained by craftbenching gold ingots so don't forget to rename during that too.
     
  11. Offline

    cman1885

    That's it's own method. Call it when the nugget is dropped or whatever. Note: Renaming items doesn't work with plugins like MultiInv which serialize itemstacks, as they don't serialize the names.
     
  12. Offline

    gomeow

    You actually can do that, ive seen it in a plugin
     
  13. Offline

    toothplck1

    Which plugin?
     
  14. Offline

    Jogy34

    You would have to rename the gold nuggets when they are picked up by a player
     
  15. Offline

    Timr

    ItemStack is an immuatble object, meaning that you cannot change it using static methods. here's some pseudo-code to redefine a String (which also happens to be immutable)

    Code:java
    1. String boom = "BOOM";
    2. boom.toLowerCase();
    3.  
    4. System.out.println(boom); //Prints BOOM
    5.  
    6. boom = boom.toLowerCase();
    7.  
    8. System.out.println(boom); //Prints boom


    in your case, you would have to use something like:

    Code:java
    1. nugget = Namer.setName(nugget, "Nugget");
     
  16. Offline

    Appljuze

    Okay that makes sense, ill try this out

    THATS what i was looking for. Thanks! Let me try it.

    THATS what i was looking for. Thanks! Let me try it.
    Do you know offhand what the player-picked-up-an-item method is?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  17. Offline

    Jogy34

    @EventHandler
    public void pickup(PlayerPickupItemEvent event)
     
  18. Offline

    gomeow

  19. Offline

    toothplck1

Thread Status:
Not open for further replies.

Share This Page