How to add an item to a players' inventory with a colored name

Discussion in 'Plugin Development' started by lonemineah_, Aug 20, 2015.

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

    lonemineah_

    Hi! I messing around with .addItem() and couldn't find out how to add a colored name to an item. If you know how to add an item to a players' inventory with a colored name please comment below.

    Thank you!
     
  2. @lonemineah_ Create an itemstack, get the item meta, set the display name to whatever you want (colours are allowed) set the item meta, give them that item.
     
    Xtreme727 likes this.
  3. Offline

    lonemineah_

    @bwfcwalshy
    How would I add an item to a certain inventory slot?
     
    Last edited: Aug 20, 2015
  4. Offline

    cyberpwn

    You can use the slot id's here: http://wiki.vg/images/1/13/Inventory-slots.png
    You can also use the itemInHand() for their current slot they are "selected" on

    p.getInventory().setItemInHand(stack); //SETS the item stack. Replaces it if there is an item
    p.getInventory().setItem(id, stack); //sets the item stack for the slot id

    be sure to use getItemInHand() != null or getItem(slotID) != null first to make sure you dont remove their item they currently have if that is what your doing
     
  5. @cyberpwn
    That link are network slots, not inventory slots.
     
  6. Offline

    pedrinholuizf

    Try that snippet of code:

    Code:
    ItemStack item = new ItemStack(Material.AIR);
    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName("§c§lColored Name");
    item.setItemMeta(meta);
    player.getInventory().addItem(item);
    
    I'm not at home, so i can't test it now, but it should work.
     
Thread Status:
Not open for further replies.

Share This Page