diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ExcellentEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ExcellentEnchant.java index 4070b41..678c103 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ExcellentEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ExcellentEnchant.java @@ -24,11 +24,11 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; import su.nightexpress.excellentenchants.api.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.enchantment.EnchantManager; +import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.ObtainType; -import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.tier.Tier; import java.util.*; @@ -154,6 +154,28 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme } } + @NotNull + public UnaryOperator replaceAllPlaceholders(int level) { + return str -> this.replacePlaceholders(level).apply(str) + .replace(Placeholders.ENCHANTMENT_NAME, this.getDisplayName()) + .replace(Placeholders.ENCHANTMENT_NAME_FORMATTED, this.getNameFormatted(level)) + .replace(Placeholders.ENCHANTMENT_LEVEL, NumberUtil.toRoman(level)) + .replace(Placeholders.ENCHANTMENT_LEVEL_MIN, String.valueOf(this.getStartLevel())) + .replace(Placeholders.ENCHANTMENT_LEVEL_MAX, String.valueOf(this.getMaxLevel())) + .replace(Placeholders.ENCHANTMENT_TIER, this.getTier().getName()) + .replace(Placeholders.ENCHANTMENT_FIT_ITEM_TYPES, String.join(", ", Stream.of(this.getFitItemTypes()).map(type -> plugin.getLangManager().getEnum(type)).toList())) + .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_ENCHANTING, NumberUtil.format(this.getObtainChance(ObtainType.ENCHANTING))) + .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_VILLAGER, NumberUtil.format(this.getObtainChance(ObtainType.VILLAGER))) + .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_LOOT_GENERATION, NumberUtil.format(this.getObtainChance(ObtainType.LOOT_GENERATION))) + .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_FISHING, NumberUtil.format(this.getObtainChance(ObtainType.FISHING))) + .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_MOB_SPAWNING, NumberUtil.format(this.getObtainChance(ObtainType.MOB_SPAWNING))) + .replace(Placeholders.ENCHANTMENT_CHARGES_MAX_AMOUNT, String.valueOf(this.getChargesMax(level))) + .replace(Placeholders.ENCHANTMENT_CHARGES_CONSUME_AMOUNT, String.valueOf(this.getChargesConsumeAmount(level))) + .replace(Placeholders.ENCHANTMENT_CHARGES_RECHARGE_AMOUNT, String.valueOf(this.getChargesRechargeAmount(level))) + .replace(Placeholders.ENCHANTMENT_CHARGES_FUEL_ITEM, ItemUtil.getItemName(this.getChargesFuel())) + ; + } + @NotNull public UnaryOperator replacePlaceholders(int level) { return str -> { @@ -168,24 +190,7 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme .replace(PotionImplementation.PLACEHOLDER_POTION_DURATION, NumberUtil.format((double) potioned.getEffectDuration(level) / 20D)) .replace(PotionImplementation.PLACEHOLDER_POTION_TYPE, LangManager.getPotionType(potioned.getEffectType())); } - return str - .replace(Placeholders.ENCHANTMENT_NAME, this.getDisplayName()) - .replace(Placeholders.ENCHANTMENT_NAME_FORMATTED, this.getNameFormatted(level)) - .replace(Placeholders.ENCHANTMENT_LEVEL, NumberUtil.toRoman(level)) - .replace(Placeholders.ENCHANTMENT_LEVEL_MIN, String.valueOf(this.getStartLevel())) - .replace(Placeholders.ENCHANTMENT_LEVEL_MAX, String.valueOf(this.getMaxLevel())) - .replace(Placeholders.ENCHANTMENT_TIER, this.getTier().getName()) - .replace(Placeholders.ENCHANTMENT_FIT_ITEM_TYPES, String.join(", ", Stream.of(this.getFitItemTypes()).map(type -> plugin.getLangManager().getEnum(type)).toList())) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_ENCHANTING, NumberUtil.format(this.getObtainChance(ObtainType.ENCHANTING))) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_VILLAGER, NumberUtil.format(this.getObtainChance(ObtainType.VILLAGER))) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_LOOT_GENERATION, NumberUtil.format(this.getObtainChance(ObtainType.LOOT_GENERATION))) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_FISHING, NumberUtil.format(this.getObtainChance(ObtainType.FISHING))) - .replace(Placeholders.ENCHANTMENT_OBTAIN_CHANCE_MOB_SPAWNING, NumberUtil.format(this.getObtainChance(ObtainType.MOB_SPAWNING))) - .replace(Placeholders.ENCHANTMENT_CHARGES_MAX_AMOUNT, String.valueOf(this.getChargesMax(level))) - .replace(Placeholders.ENCHANTMENT_CHARGES_CONSUME_AMOUNT, String.valueOf(this.getChargesConsumeAmount(level))) - .replace(Placeholders.ENCHANTMENT_CHARGES_RECHARGE_AMOUNT, String.valueOf(this.getChargesRechargeAmount(level))) - .replace(Placeholders.ENCHANTMENT_CHARGES_FUEL_ITEM, ItemUtil.getItemName(this.getChargesFuel())) - ; + return str; }; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java index 3c862a4..3220c5e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java @@ -275,7 +275,7 @@ public class EnchantManager extends AbstractManager { return enchant == null ? null : Pair.of(enchant, entry.getValue()); }) .filter(Objects::nonNull) - .sorted(Comparator.comparing(p -> p.getFirst().getPriority(), Comparator.reverseOrder())) + //.sorted(Comparator.comparing(p -> p.getFirst().getPriority(), Comparator.reverseOrder())) .collect(Collectors.toMap(Pair::getFirst, Pair::getSecond, (old, nev) -> nev, LinkedHashMap::new)); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java index 98e9019..2c390f3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java @@ -139,7 +139,7 @@ public class EnchantmentsListMenu extends AbstractMenuAuto enchants = EnchantManager.getExcellentEnchantments(item); + Map enchants = EnchantManager.getExcellentEnchantments(item) + .entrySet().stream() + .sorted(Comparator.comparing(e -> e.getKey().getTier().getPriority())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (old,nev) -> nev, LinkedHashMap::new)); if (enchants.isEmpty()) return item; List lore = meta.getLore() == null ? new ArrayList<>() : meta.getLore(); - enchants.keySet().forEach(enchant -> lore.removeIf(line -> line.contains(enchant.getDisplayName()))); - if (isCreative) { - enchants.forEach((enchant, level) -> { - lore.removeAll(enchant.formatDescription(level)); - }); + if (!lore.isEmpty()) { + enchants.keySet().forEach(enchant -> lore.removeIf(line -> line.contains(enchant.getDisplayName()))); + if (isCreative) { + enchants.forEach((enchant, level) -> { + lore.removeAll(enchant.formatDescription(level)); + }); + } } - - enchants = enchants.entrySet().stream() - .sorted(Comparator.comparing(e -> e.getKey().getTier().getPriority())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (old,nev) -> nev, LinkedHashMap::new)); if (Config.ENCHANTMENTS_DESCRIPTION_ENABLED.get() && !isCreative) { enchants.forEach((enchant, level) -> { lore.addAll(0, enchant.formatDescription(level));