Search in sources :

Example 1 with PaperCustomEnch

use of io.zivoric.enchantmentcore.paper.PaperCustomEnch in project ZEnchantmentCore by zivoric.

the class PaperLoreHandler method updateItemLore.

@Override
public Map<CustomEnch, Integer> updateItemLore(ItemMeta meta, Map<CustomEnch, Integer> currentEnchantMap) {
    Map<CustomEnch, Integer> remaining = new HashMap<>();
    // Create enchant lore
    List<Component> createdLore = new ArrayList<>();
    // Only add lore if the item doesn't hide enchants
    boolean showEnchants = !meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS);
    currentEnchantMap.forEach((ench, level) -> {
        if (ench instanceof PaperCustomEnch) {
            if (showEnchants) {
                createdLore.add(ench.displayName(level).decoration(TextDecoration.ITALIC, false).append(ENCH_CODE));
            }
        } else {
            remaining.put(ench, level);
        }
    });
    // Add current lore
    List<Component> currentLore = meta.lore();
    if (currentLore != null) {
        for (Component comp : currentLore) {
            if (!comp.children().contains(ENCH_CODE)) {
                // Should not contain enchant lore
                createdLore.add(comp);
            }
        }
    }
    // Set lore to item meta
    if (!createdLore.equals(currentLore)) {
        meta.lore(createdLore.isEmpty() ? null : createdLore);
    }
    return remaining;
}
Also used : PaperCustomEnch(io.zivoric.enchantmentcore.paper.PaperCustomEnch) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PaperCustomEnch(io.zivoric.enchantmentcore.paper.PaperCustomEnch) CustomEnch(io.zivoric.enchantmentcore.CustomEnch) Component(net.kyori.adventure.text.Component)

Aggregations

CustomEnch (io.zivoric.enchantmentcore.CustomEnch)1 PaperCustomEnch (io.zivoric.enchantmentcore.paper.PaperCustomEnch)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Component (net.kyori.adventure.text.Component)1