Solved Item meta lore code???

Discussion in 'Plugin Development' started by vhbob, Dec 5, 2015.

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

    vhbob

    Hey, im coding a plugin and i cant figure out how to write the lore, i tried what i did with the item name but it did'nt work, please help. code:
    Code:
    ItemStack fly = new ItemStack(Material.STRING);
                    ItemMeta flym = fly.getItemMeta();
                    flym.setDisplayName(ChatColor.WHITE + "The Ability to Fly!");
                    flym.setLore(ChatColor.GOLD + "1000 VC");
     
  2. Offline

    Scimiguy

    You have to set the ItemMeta back on the item after you're done.

    fly.setItemMeta(flym);
     
  3. Offline

    vhbob

    @Scimiguy the error is with this line, it says " The method setLore(List<String>) in the type ItemMeta is not applicable for the arguments (String) " Heres the line thats making the error
    Code:
    flym.setLore(ChatColor.GOLD + "1000 VC");
     
  4. Offline

    Scimiguy

    Because Lore is a List of Strings.

    use getLore() first, and edit the List that it gives you.
     
  5. Offline

    vhbob

    @Scimiguy this gives the same error :
    Code:
    flym.setLore(flym.getLore().set(1,ChatColor.GOLD + "1000 VC" ));
     
  6. Offline

    Scimiguy

    Don't do that, you haven't even check if lore != null.

    ItemMeta meta = ItemStack#getItemMeta();
    List<String> lore = meta.getLore();
    if (lore == null)
    lore == new ArrayList<String>();

    Then deal with setting strings.
    use List#add(int index, String element)
    then set it back to the meta
    meta.setLore()
    Then back to the item
    item.setItemMeta()
     
  7. Offline

    vhbob

    @Scimiguy okay, thanks

    @Scimiguy i did this but it doesn't work, it says internal error occoured :
    Code:
    if (command.getName().equalsIgnoreCase("shop")) {
                    ItemStack fly = new ItemStack(Material.STRING);
                    ItemMeta flym = fly.getItemMeta();
                    flym.setDisplayName(ChatColor.WHITE + "The Ability to Fly!");
                    List<String> lore = flym.getLore();
                    lore.set(1 , ChatColor.GOLD + "1000 VC" );
                    fly.setItemMeta(flym);
                    i.setItem(0, fly);
                    p.openInventory(i);
                }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 5, 2015
  8. Offline

    mcdorli

    You still don't check, if the lore is null, tgat's the problem. Please read what others say you. You need to create a bew arraylist, then set it as the lore later
     
  9. Offline

    vhbob

    @mcdorli i have done this, it is still uneffective
    Code:
    if (command.getName().equalsIgnoreCase("shop")) {
                    ItemStack fly = new ItemStack(Material.STRING);
                    ItemMeta flym = fly.getItemMeta();
                    flym.setDisplayName(ChatColor.WHITE + "The Ability to Fly!");
                    List<String> lore = flym.getLore();
                    if (lore == null) {
                        lore.set(1, ChatColor.GOLD + "1000 VC");
                        flym.setLore(lore);
                        fly.setItemMeta(flym);
                        i.setItem(0, fly);
                        p.openInventory(i);
                    }
                }
     
  10. Offline

    Scimiguy

    Really?
    You don't see why it's ineffective?

    I mean these two lines alone should be enough to tell you why
    1. if (lore == null) {
    2. lore.set(1, ChatColor.GOLD + "1000 VC");
     
  11. Offline

    vhbob

    @Scimiguy Thanks, i did this and it worked :)
    Code:
    if (command.getName().equalsIgnoreCase("shop")) {
                    ItemStack fly = new ItemStack(Material.STRING);
                    ItemMeta flym = fly.getItemMeta();
                    flym.setDisplayName(ChatColor.WHITE + "The Ability to Fly!");
                    List<String> lore = flym.getLore();
                    if (lore == null) {
                        lore = new ArrayList<String>();
                        lore.add(ChatColor.GOLD + "1000 VC");
                        flym.setLore(lore);
                        fly.setItemMeta(flym);
                        i.setItem(0, fly);
                        p.openInventory(i);
                    }
                }
     
    Last edited: Dec 5, 2015
Thread Status:
Not open for further replies.

Share This Page