Solved Can't get lore working

Discussion in 'Spigot Plugin Development' started by ZBLL, Jul 16, 2021.

Thread Status:
Not open for further replies.
  1. Code (Java):

    String firstEnchLore = c("&7" + e1.getName() + " " + Common.translateRomanToArabic(firstSuggestion.getEnchantmentLevel(e1)));
    String secondEnchLore = c("&7" + e2.getName() + " " + Common.translateRomanToArabic(firstSuggestion.getEnchantmentLevel(e2)));
    String thirdEnchLore = c("&7" + e3.getName() + " " + Common.translateRomanToArabic(firstSuggestion.getEnchantmentLevel(e3)));

    ItemMeta firstMeta = firstSuggestion.getItemMeta();
    ItemMeta secondMeta = secondSuggestion.getItemMeta();
    ItemMeta thirdMeta = thirdSuggestion.getItemMeta();

    firstMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    secondMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    thirdMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);

    firstMeta.setLore(Collections.singletonList(firstEnchLore));
    secondMeta.setLore(Collections.singletonList(secondEnchLore));
    thirdMeta.setLore(Collections.singletonList(thirdEnchLore));

    firstSuggestion.setItemMeta(firstMeta);
    secondSuggestion.setItemMeta(secondMeta);
    thirdSuggestion.setItemMeta(thirdMeta);
     
    This is some simple code that doesn't work, and by that I mean that the lore is not showing up: https://prnt.sc/1bpzs74
     
  2. Enchanted books are NOT enchanted!
    They work differently from enchanted items.
    Instead, get their ItemMeta, cast it to EnchantmentStorageMeta, and get their enchantments from there.
     
    • Like Like x 1
  3. The strings of lore exist. I debugged it and strings firstEnchLore, secondEnchLore, etc. are not empty. I have enchanted the books myself with addUnsafeEnchantment. So in this case they are very enchanted but I can't put the lore to work.
     
  4. Try removing all ItemFlags and then setting HIDE_ENCHANTS.
    Also, do you get any errors in the console?
     
  5. I don't get any errors. Alright, let me do that
     
  6. Removing the flags doesn't do anything.
     
  7. I want you to test something: change the item's type to some other Material (sword/stone/dirt) before doing all that stuff and let me know if that works.
     
  8. I just tried doing it with a normal book
     
  9. I'm guessing it didn't work... Then I'm guessing there's a problem with displaying lore on books.
    Try from scratch but use some sword with sharpness on it - I want to see if this is actually a problem with books not displaying the lore to you or everything.
     
  10. That's the entire point of this thread. The strings for the lore exist, but the lore itself doesn't
     
  11. I think I figured the reason - I put the items in the GUI before adding the lore. Let me test that
     
  12. That was the case :D
     
Thread Status:
Not open for further replies.