Tutorial - Renaming Items

Discussion in 'Resources' started by JPG2000, Sep 1, 2013.

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

    JPG2000

    For Steps 1-5, you are expected to have your onCommand method, as well as your onEnable and onDisable ready, with your Plugin.yml.

    1: Create the ItemStack. I am going to create a ItemStack names IceCream, and make it 1 piece of Sugar.
    Code:java
    1. ItemStack IceCream = new ItemStack(Material.SUGAR, 1);


    2: We are going to make the ItemMeta. I am going to call it IceCreamMeta.
    Code:java
    1. ItemMeta IceCreamMeta = IceCream.getItemMeta();


    3: This is where we do the actually renaming. You can use IceCreamMeta. to see a list, but I am just going to rename it. Also, this works with ChatColors.
    Code:java
    1. IceCreamMeta.setDisplayName("IceCream");


    4: We are now going to rap this up. We need to set IceCream to IceCreamMeta.
    Code:java
    1. IceCream.setItemMeta(IceCreamMeta);


    5: OPTIONAL: You can now give it to the player's inventory.
    Code:java
    1. Inventory pi = player.getInventory();
    2. pi.addItem(IceCream)



    The Final Product:
    Code:java
    1. if (alias.equalsIgnoreCase("GiveMeIceCream")) {
    2. Player player = (Player) sender;
    3. Inventory pi = player.getInventory();
    4.  
    5. ItemStack IceCream = new ItemStack(Material.SUGAR, 1);
    6. ItemMeta IceCreamMeta = IceCream.getItemMeta();
    7. IceCreamMeta.setDisplayName("IceCream");
    8. IceCream.setItemMeta(IceCreamMeta);
    9.  
    10. pi.addItem(IceCream);
    11. }


     
  2. JPG2000 Message a mod and ask them to move, but good, simple tutorial.
     
  3. Offline

    xTrollxDudex

    JPG2000
    Chasechocolate is DBO staff, we need a forum mod to do this :p

    JPG2000
    I really shouldn't tahg staff, but here goes nothing: Jade

    Otherwise, it's fine although many people can just look up "How to name items Bukkit" on google. On the other hand, some people are too stupid to do so...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
    chasechocolate likes this.
  4. Offline

    Jade

    xTrollxDudex Banned for tagging staff. jkay.

    Moved to correct section.
     
    xTrollxDudex likes this.
  5. Offline

    chasechocolate

    Jade likes this.
  6. Offline

    xTrollxDudex

    chasechocolate
    I did. But then Jade came to the rescue 26 minutes later, which I have to say, is responding to a 911 call and finding the house completely obliterated by the fire :/. Well. Would've taken more time than tagging :p maybe Jade should get one of those page reloader thingys like chaseos has.
     
    KrazyRaven likes this.
Thread Status:
Not open for further replies.

Share This Page