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;
}
Aggregations