diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java index c4916482..a30b4b32 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java @@ -51,8 +51,8 @@ public class Abilities extends ItemStat return list; } - private String generalFormat, modifierIfAny, modifierForEach, modifierSplitter, abilitySplitter; - private boolean legacyFormat, useAbilitySplitter; + private String generalFormat, modifierIfAny, modifierForEach, modifierSplitter, abilitySplitter, modifierNewLine; + private boolean useAbilitySplitter; private int modifiersPerLine; @BackwardsCompatibility(version = "6.10") @@ -61,17 +61,21 @@ public class Abilities extends ItemStat // COMPATIBILITY CODE FOR MI <6.10 if (!(configObject instanceof ConfigurationSection)) { - legacyFormat = true; generalFormat = legacyLanguageFile.getString("ability-format"); + modifierIfAny = "\n"; + modifierNewLine = "\n"; modifierForEach = legacyLanguageFile.getString("ability-modifier"); + modifierSplitter = ""; abilitySplitter = legacyLanguageFile.getString("ability-splitter"); useAbilitySplitter = abilitySplitter != null && !abilitySplitter.isEmpty(); + modifiersPerLine = 1; return; } final ConfigurationSection config = (ConfigurationSection) configObject; generalFormat = config.getString("general-format"); - modifierIfAny = config.getString("modifier-if-any"); + modifierIfAny = config.getString("modifier-if-any", ""); // Backwards compatibility + modifierNewLine = "\n" + config.getString("modifier-new-line", ""); // Backwards compatibility modifierForEach = config.getString("modifier-foreach"); modifierSplitter = config.getString("modifier-splitter"); abilitySplitter = config.getString("ability-splitter.format"); @@ -81,65 +85,40 @@ public class Abilities extends ItemStat @Override public void whenApplied(@NotNull ItemStackBuilder item, @NotNull AbilityListData data) { + final List abilityLore = new ArrayList<>(); - // Modify Lore - List abilityLore = new ArrayList<>(); + data.getAbilities().forEach(ability -> { + final StringBuilder builder = new StringBuilder(generalFormat + .replace("{trigger}", MMOItems.plugin.getLanguage().getCastingModeName(ability.getTrigger())) + .replace("{ability}", ability.getAbility().getName())); - // DEPRECATED CODE which supports old versions of the stats.yml config - if (legacyFormat) { - data.getAbilities().forEach(ability -> { - abilityLore.add(generalFormat - .replace("{trigger}", MMOItems.plugin.getLanguage().getCastingModeName(ability.getTrigger())) - .replace("{ability}", ability.getAbility().getName())); + if (!ability.getModifiers().isEmpty()) builder.append(modifierIfAny); - for (String modifier : ability.getModifiers()) { - item.getLore().registerPlaceholder("ability_" + ability.getAbility().getHandler().getId().toLowerCase() + "_" + modifier, - MythicLib.plugin.getMMOConfig().decimals.format(ability.getParameter(modifier))); - abilityLore.add(modifierForEach.replace("{modifier}", ability.getAbility().getParameterName(modifier)).replace("{value}", - MythicLib.plugin.getMMOConfig().decimals.format(ability.getParameter(modifier)))); + boolean newLine = false; + int lineCounter = 0; + for (String modifier : ability.getModifiers()) { + final String formattedValue = MythicLib.plugin.getMMOConfig().decimals.format(ability.getParameter(modifier)); + item.getLore().registerPlaceholder("ability_" + ability.getAbility().getHandler().getId().toLowerCase() + "_" + modifier, formattedValue); + builder.append(newLine ? modifierNewLine : modifierSplitter); + builder.append(modifierForEach + .replace("{modifier}", ability.getAbility().getParameterName(modifier)) + .replace("{value}", formattedValue)); + newLine = false; + lineCounter++; + + if (modifiersPerLine > 0 && lineCounter >= modifiersPerLine) { + lineCounter = 0; + newLine = true; } + } - if (useAbilitySplitter) - abilityLore.add(abilitySplitter); - }); - } + abilityLore.add(builder.toString()); - // Up to date code - else { - data.getAbilities().forEach(ability -> { - final StringBuilder builder = new StringBuilder(generalFormat - .replace("{trigger}", MMOItems.plugin.getLanguage().getCastingModeName(ability.getTrigger())) - .replace("{ability}", ability.getAbility().getName())); + if (useAbilitySplitter) + abilityLore.add(abilitySplitter); + }); - if (!ability.getModifiers().isEmpty()) builder.append(modifierIfAny); - - boolean modifierAppened = false; - int lineCounter = 0; - for (String modifier : ability.getModifiers()) { - final String formattedValue = MythicLib.plugin.getMMOConfig().decimals.format(ability.getParameter(modifier)); - item.getLore().registerPlaceholder("ability_" + ability.getAbility().getHandler().getId().toLowerCase() + "_" + modifier, formattedValue); - if (modifierAppened) builder.append(modifierSplitter); - builder.append(modifierForEach - .replace("{modifier}", ability.getAbility().getParameterName(modifier)) - .replace("{value}", formattedValue)); - modifierAppened = true; - lineCounter++; - - if (modifiersPerLine > 0 && lineCounter >= modifiersPerLine) { - lineCounter = 0; - modifierAppened = false; - builder.append("\n"); // Will be processed later on by MMOItems - } - } - - abilityLore.add(builder.toString()); - - if (useAbilitySplitter) - abilityLore.add(abilitySplitter); - }); - } - - if (useAbilitySplitter && abilityLore.size() > 0) + if (useAbilitySplitter && !abilityLore.isEmpty()) abilityLore.remove(abilityLore.size() - 1); // Modify tags