Item Lores

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

  1. Hey! I've been trying for almost 30 minutes, searching the api's everything. To make a lore for my ItemMeta, here is the code that says would work. But somehow I can't get it working D:
    Code (Text):
    [itemmeta].setLore("Hey");
    If someone knows how to see the issue to my problem, please post it. I'm struggling greatly.
    Thanks - Mansion
     
    • Friendly Friendly x 1
  2. #setLore takes a parameter of a String list.

    Most people use Arrays#asList for this, then your lore inside.
     
  3. Be sure to set the items meta afterwards.

    Code (Java):
    [item].setItemMeta([itemmeta]);
    Lore is a StringList, not a string.

    Code (Java):
    [itemmeta].setLore(Arrays.asList("lore"))
     
    • Agree Agree x 1
  4. Use Arrays.asList("Line1", "Line2", "Etc");
     
    • Agree Agree x 1
  5. Thanks guys so much, I got it working from;
    , But you guys all helped. Thanks so much <3
     
  6. Thanks all, but how would I make it so I can add 2 lines?
    Solved
     
    #6 ItsWill, May 15, 2015
    Last edited: May 16, 2015
  7. @mansionwill well... Arrays.asList uses varargs, which means it accepts 0 to (theoretically) infinite parameters.
     
    • Agree Agree x 1
  8. Yeah, that's what I found out. Thank you.
     
  9. You can just add this to your main class or somewhere:

    Code (Text):
    public static void addLore(ItemStack i, String s) {
            if (i.getItemMeta().getLore() == null) {
                List lore = new ArrayList();
                lore.add(s);
                ItemMeta imeta = i.getItemMeta();
                imeta.setLore(lore);
                i.setItemMeta(imeta);
            } else {
                List lore = i.getItemMeta().getLore();
                lore.add(s);
                ItemMeta imeta = i.getItemMeta();
                imeta.setLore(lore);
                i.setItemMeta(imeta);
            }
        }
    and now you can use this little "api" in every other class of your plugin like this:
    [YourClassTheCodeAboveIsIn].addLore([YourItemStack], "Lore");
    example:
    Code (Text):
    ItemStack test = new ItemStack(Material.DIRT);
    Main.addLore(test, ChatColor.RED + "This is just a test lore);
    Main.addLore(test, ChatColor.BLUE + "lol");
    You can add as many Lores you want for sure.
     
  10. Thank You.
     
    • Informative Informative x 1
  11. Hello, how to remove "+7 points attack" lore ?
    Can I use Meta.setLore(null); ?
     
  12. It's so easy to make your own post... No need to necro.
     
  13. It's so easy to answer quickly.... Moreover we are on July 20, 2015 and this post May 16, 2015...
    If I google "remove lore" I found only few page but this was the most revealant
     
  14. No. You need to change (or set) NBT-tag "HideFlags"of item.
     
  15. HideFlags => Minecraft 1.8 => no thanks.

    Moreover I just need to remove lore for one sword for my compass navigation.