Custom Item Name?

Discussion in 'Plugin Development' started by coolguy4744, Apr 22, 2014.

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

    coolguy4744

    Sorry, this is my 2nd bug within' the hour. XD
    I have been looking all the the forums for a solution but I cannot find one. The issue is that I would like to the bedrock to look like this

    ChatColor.DARK_GREEN + "" + ChatColor.BOLD "Member Kits");

    With a lore of

    ChatColor.YELLOW + "Right click to use");

    And I cannot seem to get it with lore or with setDisplayName. Here is my code for spawning the bedrock.

    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event) {
    3. event.getPlayer().getInventory()
    4. .addItem(new ItemStack(Material.BEDROCK));
     
  2. Offline

    Wizehh

    First create a new ItemStack object so that you can refer to it later:
    PHP:
    ItemStack i = new ItemStack(Material.BEDROCK);
    Then, you can change the display name and lore by getting the ItemStack's ItemMeta:
    PHP:
    i.getItemMeta().setDisplayName("Name");
    List<
    Stringlore = new ArrayList<String>();
    lore.add("Lore!");
    i.getItemMeta().setLore(lore);
     
  3. Offline

    coolguy4744

    Wizehh
    I tried that, when I keep the
    .addItem(new ItemStack(Material.BEDROCK));

    With all of that it is just normal bedrock, but when I remove it nothing happens. :/
     
  4. Offline

    Wizehh

    I don't understand what you're asking.
     
  5. Offline

    coolguy4744

    Wizehh
    I want them to have bedrock with this on it when ever they join.

    ChatColor.DARK_GREEN + "" + ChatColor.BOLD "Member Kits");

    With a lore of

    ChatColor.YELLOW + "Right click to use");
     
  6. Offline

    Wizehh

    What's the problem? I just supplied you with the code to do that. If you want the bedrock to be placed and then still have the display name/lore.. well, I don't think that's possible.
     
  7. Offline

    coolguy4744

    Wizehh
    But the do I need to add a extra line for them to be able to have it when they join?
     
  8. Offline

    Wizehh

    Like this?
    PHP:
    event.getPlayer().getInventory().addItem(i);
     
  9. Offline

    coolguy4744

    Wizehh
    Yes that does it but it does not add the name or lore. :/
     
  10. Offline

    Wizehh

    Absolute spoon-feed:
    PHP:
    ItemStack i = new ItemStack(Material.BEDROCK);
    ItemMeta m i.getItemMeta();
    m.setDisplayName("Display Name");
    List<
    Stringlore = new ArrayList<String>();
    lore.add("Lore");
    m.setLore(lore);
    i.setItemMeta(m);
    // give item to player
     
    coolguy4744 likes this.
  11. Offline

    coolguy4744

    Wizehh
    Didn't work. .-.

    Ah no worries, sorted it. Thanks man! :p

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

    Anonymous350

    coolguy4744

    I don't get how it doesn't work, Wizehh is obviously telling you what to-do yet you have issues.


    Code:java
    1. if(label.equalsIgnoreCase("kits")) {
    2. ItemStack br = new ItemStack(Material.BEDROCK);
    3. ItemMeta brMeta = br.getItemMeta();
    4. brMeta.setDisplayName(String.format("%s%sMember Kits", ChatColor.DARK_GREEN , ChatColor.BOLD));
    5. List<String> lore = new ArrayList<String>();
    6. lore.add(ChatColor.DARK_AQUA + "Right click to use");
    7. brMeta.setLore(lore);
    8. br.setItemMeta(brMeta);
    9. player.getInventory().addItem(br);
    10. }
    11.  


    Make sure you imported:

    Code:java
    1. import java.util.ArrayList;
    2. import java.util.List;
     
  13. Offline

    coolguy4744

    Anonymous350



    I forgot to add the
    Code:java
    1. event.getPlayer().getInventory().addItem(i);
     
Thread Status:
Not open for further replies.

Share This Page