Solved [HELP REQUEST] Naming items

Discussion in 'Plugin Development' started by DaanHai, Jun 25, 2014.

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

    DaanHai

    I'm trying to learn how to make plugins, but got stuck on this one. I want to make a plugin that gives a player some items when they join. When these items are clicked, a GUI opens. This just works normally, but I can't figure out how to rename the items. This is the code I got, which doesn't work:

    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event) {
    3. ItemStack joinItem = new ItemStack(Material.EMERALD);
    4. ItemMeta joinItemMeta = joinItem.getItemMeta();
    5. joinItemMeta.setDisplayName("NAME");
    6. joinItem.setItemMeta(joinItemMeta);
    7. event.getPlayer().getInventory().addItem(joinItem);
    8. }


    Of course, just as I posted this request, I got it..
    Here's the new code:

    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event) {
    3. ItemStack joinEmerald = new ItemStack(Material.EMERALD);
    4. ItemMeta itemMeta = joinEmerald.getItemMeta();
    5. itemMeta.setDisplayName(ChatColor.GREEN + "Teleporter");
    6. joinEmerald.setItemMeta(itemMeta);
    7. event.getPlayer().getInventory().addItem(joinEmerald);
    8. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page