ItemMeta & ItemStack Aren't Working?

Discussion in 'Spigot Plugin Development' started by ItsWill, May 13, 2015.

  1. PHP:
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            ItemStack star2 = new ItemStack(Material.NETHER_STAR);
            ItemMeta starr = star2.getItemMeta();
            player.getInventory().setItem(8, star2);
            starr.setDisplayName(ChatColor.WHITE + "" + ChatColor.BOLD + "Server Selector");
    That is my code. Everything else works but the name
    starr.setDisplayName(ChatColor.WHITE + "" + ChatColor.BOLD + "Server Selector");
    If you could help that would be fantastic and would make my day :D
    NOTE: Just Joined :)
    #1 ItsWill, May 13, 2015
    Last edited: May 13, 2015
  2. You're setting the item meta and adding the item to the player's inventory before you manipulate the item's display name. To put this in other terms, you're doing the following:
    Code (Text):
    1. Creating new ItemStack
    2. Getting the ItemMeta
    3. Setting the ItemMeta
    4. Adding the item to the inventory
    5. Manipulating the ItemMeta.
    But, what you need to do, is the following:
    Code (Text):
    1. Create new ItemStack
    2. Get the ItemMeta
    3. Set the Display Name
    4. Set the ItemMeta
    5. Add the item to the inventory
    • Like Like x 1
  3. Thanks! I'll try this, and let you know how it went. Thanks!
    Thank you so much.
    #3 ItsWill, May 14, 2015
    Last edited: May 14, 2015
  4. You have to set the displayName before setting the ItemMeta.
    • Agree Agree x 1