diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/menus/abilities/AbilitiesComponents.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/menus/abilities/AbilitiesComponents.java index a9688812f..6446e052e 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/menus/abilities/AbilitiesComponents.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/menus/abilities/AbilitiesComponents.java @@ -6,12 +6,12 @@ import com.archyx.slate.menu.ActiveMenu; import dev.aurelium.auraskills.api.ability.Ability; import dev.aurelium.auraskills.api.ability.AbstractAbility; -import dev.aurelium.auraskills.api.mana.ManaAbilities; import dev.aurelium.auraskills.api.mana.ManaAbility; +import dev.aurelium.auraskills.api.util.NumberUtil; import dev.aurelium.auraskills.bukkit.AuraSkills; import dev.aurelium.auraskills.bukkit.menus.AbstractComponent; +import dev.aurelium.auraskills.common.ability.AbilityUtil; import dev.aurelium.auraskills.common.user.User; -import dev.aurelium.auraskills.api.util.NumberUtil; import dev.aurelium.auraskills.common.util.math.RomanNumber; import dev.aurelium.auraskills.common.util.text.Replacer; import dev.aurelium.auraskills.common.util.text.TextUtil; @@ -74,15 +74,18 @@ public String onPlaceholderReplace(String placeholder, Player player, Active Locale locale = plugin.getUser(player).getLocale(); if (placeholder.equals("desc")) { User user = plugin.getUser(player); + String format = activeMenu.getFormat("desc_upgrade_value"); if (context instanceof Ability ability) { + int level = user.getAbilityLevel(ability); return TextUtil.replace(ability.getDescription(locale), - "{value}", getUpgradeValue(ability, user, activeMenu), - "{value_2}", getUpgradeValue2(ability, user, activeMenu)); + "{value}", AbilityUtil.getUpgradeValue(ability, level, format), + "{value_2}", AbilityUtil.getUpgradeValue2(ability, level, format)); } else if (context instanceof ManaAbility manaAbility) { + int level = user.getManaAbilityLevel(manaAbility); return TextUtil.replace(manaAbility.getDescription(locale), - "{value}", getUpgradeValue(manaAbility, user, activeMenu), + "{value}", AbilityUtil.getUpgradeValue(manaAbility, level, format), "{haste_level}", String.valueOf(manaAbility.optionInt("haste_level", 10)), - "{duration}", getUpgradeDuration(manaAbility, user, activeMenu)); + "{duration}", AbilityUtil.getUpgradeDuration(manaAbility, level, format)); } } return replaceMenuMessage(placeholder, player, activeMenu, new Replacer() @@ -101,46 +104,6 @@ private int getNextUpgradeLevel(AbstractAbility ability, User user) { return unlock + levelUp * user.getAbstractAbilityLevel(ability); } - private String getCurrentValue(Ability ability, User user) { - return NumberUtil.format1(ability.getValue(user.getAbilityLevel(ability))); - } - - private String getCurrentValue2(Ability ability, User user) { - return NumberUtil.format1(ability.getSecondaryValue(user.getAbilityLevel(ability))); - } - - private String getUpgradeValue(Ability ability, User user, ActiveMenu activeMenu) { - String currentValue = getCurrentValue(ability, user); - String nextValue = NumberUtil.format1(ability.getValue(user.getAbilityLevel(ability) + 1)); - return TextUtil.replace(activeMenu.getFormat("desc_upgrade_value"), - "{current}", currentValue, - "{next}", nextValue); - } - - private String getUpgradeValue2(Ability ability, User user, ActiveMenu activeMenu) { - String currentValue = getCurrentValue2(ability, user); - String nextValue = NumberUtil.format1(ability.getSecondaryValue(user.getAbilityLevel(ability) + 1)); - return TextUtil.replace(activeMenu.getFormat("desc_upgrade_value"), - "{current}", currentValue, - "{next}", nextValue); - } - - private String getUpgradeValue(ManaAbility manaAbility, User user, ActiveMenu activeMenu) { - String currentValue = NumberUtil.format1(manaAbility.getDisplayValue(user.getManaAbilityLevel(manaAbility))); - String nextValue = NumberUtil.format1(manaAbility.getDisplayValue(user.getManaAbilityLevel(manaAbility) + 1)); - return TextUtil.replace(activeMenu.getFormat("desc_upgrade_value"), - "{current}", currentValue, - "{next}", nextValue); - } - - private String getUpgradeDuration(ManaAbility manaAbility, User user, ActiveMenu activeMenu) { - String currentDuration = NumberUtil.format1(getDuration(manaAbility, user.getManaAbilityLevel(manaAbility))); - String nextDuration = NumberUtil.format1(getDuration(manaAbility, user.getManaAbilityLevel(manaAbility) + 1)); - return TextUtil.replace(activeMenu.getFormat("desc_upgrade_value"), - "{current}", currentDuration, - "{next}", nextDuration); - } - } public static class UnlockedDescMaxed extends AbstractComponent implements ComponentProvider { @@ -162,7 +125,7 @@ public String onPlaceholderReplace(String placeholder, Player player, Active return TextUtil.replace(manaAbility.getDescription(locale), "{value}", NumberUtil.format1(manaAbility.getDisplayValue(user.getManaAbilityLevel(manaAbility))), "{haste_level}", String.valueOf(manaAbility.optionInt("haste_level", 10)), - "{duration}", NumberUtil.format1(getDuration(manaAbility, user.getManaAbilityLevel(manaAbility)))); + "{duration}", NumberUtil.format1(AbilityUtil.getDuration(manaAbility, user.getManaAbilityLevel(manaAbility)))); } } return replaceMenuMessage(placeholder, player, activeMenu); @@ -185,14 +148,4 @@ private static boolean isNotMaxed(User user, AbstractAbility ability) { return user.getAbstractAbilityLevel(ability) < maxLevel; } - private static double getDuration(ManaAbility manaAbility, int level) { - if (manaAbility == ManaAbilities.LIGHTNING_BLADE) { - double baseDuration = ManaAbilities.LIGHTNING_BLADE.optionDouble("base_duration"); - double durationPerLevel = ManaAbilities.LIGHTNING_BLADE.optionDouble("duration_per_level"); - return baseDuration + (durationPerLevel * (level - 1)); - } else { - return manaAbility.getValue(level); - } - } - } diff --git a/bukkit/src/main/resources/messages/messages_de.yml b/bukkit/src/main/resources/messages/messages_de.yml index 89bb77922..8feb96f58 100644 --- a/bukkit/src/main/resources/messages/messages_de.yml +++ b/bukkit/src/main/resources/messages/messages_de.yml @@ -562,12 +562,14 @@ leveler: subtitle: "{old} ➜ {new}" level_up: "----------------------------------------\n Fähigkeiten Levelaufstieg! {skill} {old}➜{new}\n \n Belohnung:{stat_level}{ability_unlock}{ability_level_up}{mana_ability_unlock}{mana_ability_level_up}{money_reward}\n----------------------------------------" stat_level: "\n {color}+{num}{symbol} {stat}" - ability_unlock: "\n Fähigkeit freigeschaltet! {ability} wurde freigeschaltet" - ability_level_up: "\n Fähigkeiten Levelaufstieg! {ability} ist nun Level {level}" - mana_ability_unlock: "\n Manafähigkeit freigeschaltet! {mana_ability} wurde freigeschaltet" - mana_ability_level_up: "\n Manafähigkeiten Levelaufstieg! {mana_ability} ist nun Level {level}" + ability_unlock: "\n Fähigkeit freigeschaltet! {ability} wurde freigeschaltet\n {desc}" + ability_level_up: "\n Fähigkeiten Levelaufstieg! {ability} ist nun Level {level}\n {desc}" + mana_ability_unlock: "\n Manafähigkeit freigeschaltet! {mana_ability} wurde freigeschaltet\n {desc}" + mana_ability_level_up: "\n Manafähigkeiten Levelaufstieg! {mana_ability} ist nun Level {level}\n {desc}" money_reward: "\n ${amount}" unclaimed_item: "Du hast unbeanspruchte Gegenstände, weil dein Inventar voll war, benutze /Skills um to sie zu beanspruchen" + desc_upgrade_value: "{current}→{next}" + desc_wrap: " " menus: common: close: "Schließen" @@ -1086,4 +1088,4 @@ units: mana: Mana hp: LP xp: EP -file_version: 30 +file_version: 31 diff --git a/bukkit/src/main/resources/messages/messages_en.yml b/bukkit/src/main/resources/messages/messages_en.yml index 1daef73d9..4fbc469d8 100644 --- a/bukkit/src/main/resources/messages/messages_en.yml +++ b/bukkit/src/main/resources/messages/messages_en.yml @@ -562,12 +562,14 @@ leveler: subtitle: "{old} ➜ {new}" level_up: "----------------------------------------\n Skill Level Up! {skill} {old}➜{new}\n \n Rewards:{stat_level}{ability_unlock}{ability_level_up}{mana_ability_unlock}{mana_ability_level_up}{money_reward}\n----------------------------------------" stat_level: "\n {color}+{num}{symbol} {stat}" - ability_unlock: "\n Ability Unlock! {ability} has been unlocked" - ability_level_up: "\n Ability Level Up! {ability} is now level {level}" - mana_ability_unlock: "\n Mana Ability Unlock! {mana_ability} has been unlocked" - mana_ability_level_up: "\n Mana Ability Level Up! {mana_ability} is now level {level}" + ability_unlock: "\n Ability Unlock! {ability}\n {desc}" + ability_level_up: "\n Ability Level Up! {ability} {previous}→{level}\n {desc}" + mana_ability_unlock: "\n Mana Ability Unlock! {mana_ability}\n {desc}" + mana_ability_level_up: "\n Mana Ability Level Up! {mana_ability} {previous}→{level}\n {desc}" money_reward: "\n ${amount}" unclaimed_item: "You have unclaimed items because your inventory was full, use /skills claimitems to claim them" + desc_upgrade_value: "{current}→{next}" + desc_wrap: " " menus: common: close: "Close" @@ -1086,4 +1088,4 @@ units: mana: Mana hp: HP xp: XP -file_version: 30 \ No newline at end of file +file_version: 31 \ No newline at end of file diff --git a/bukkit/src/main/resources/messages/messages_es.yml b/bukkit/src/main/resources/messages/messages_es.yml index f7185ce38..d8cfdfaf1 100644 --- a/bukkit/src/main/resources/messages/messages_es.yml +++ b/bukkit/src/main/resources/messages/messages_es.yml @@ -562,12 +562,14 @@ leveler: subtitle: "{old} ➜ {new}" level_up: "----------------------------------------\n ¡Nuevo Nivel! {skill} {old}➜{new}\n \n Recompensas:{stat_level}{ability_unlock}{ability_level_up}{mana_ability_unlock}{mana_ability_level_up}{money_reward}\n----------------------------------------" stat_level: "\n {color}+{num}{symbol} {stat}" - ability_unlock: "\n ¡Habilidad Desbloqueada! {ability} ha sido desbloqueada" - ability_level_up: "\n ¡Nuevo Nivel de Habilidad! {ability} es ahora nivel {level}" - mana_ability_unlock: "\n ¡Habilidad de Maná Desbloqueada! {mana_ability} se ha desbloqueado" - mana_ability_level_up: "\n ¡Nuevo Nivel de Habilidad de Maná! {mana_ability} es ahora nivel {level}" + ability_unlock: "\n ¡Habilidad Desbloqueada! {ability} ha sido desbloqueada\n {desc}" + ability_level_up: "\n ¡Nuevo Nivel de Habilidad! {ability} es ahora nivel {level}\n {desc}" + mana_ability_unlock: "\n ¡Habilidad de Maná Desbloqueada! {mana_ability} se ha desbloqueado\n {desc}" + mana_ability_level_up: "\n ¡Nuevo Nivel de Habilidad de Maná! {mana_ability} es ahora nivel {level}\n {desc}" money_reward: "\n ${amount}" unclaimed_item: "Tienes objetos sin reclamar porque tu invnetario estaba lleno, usa /skills claimitems para reclamarlos" + desc_upgrade_value: "{current}→{next}" + desc_wrap: " " menus: common: close: "Cerrar" @@ -1086,4 +1088,4 @@ units: mana: Maná hp: HP xp: XP -file_version: 30 +file_version: 31 diff --git a/bukkit/src/main/resources/messages/messages_fr.yml b/bukkit/src/main/resources/messages/messages_fr.yml index b67c9caf6..1f0de9043 100644 --- a/bukkit/src/main/resources/messages/messages_fr.yml +++ b/bukkit/src/main/resources/messages/messages_fr.yml @@ -562,12 +562,14 @@ leveler: subtitle: "{old} ➜ {new}" level_up: "----------------------------------------\n Niveau supérieur! {skill} {old}➜{new} \n \n Récompenses:{stat_level}{ability_unlock}{ability_level_up}{mana_ability_unlock}{mana_ability_level_up}{money_reward}\n----------------------------------------" stat_level: "\n {color}+{num}{symbol} {stat}" - ability_unlock: "\n Compétence débloquée! {ability} a été débloquée" - ability_level_up: "\n Niveau de compétence supérieur! {ability} est maintenant niveau {level}" - mana_ability_unlock: "\nCapacité de mana débloquée! {mana_ability} a été débloquée" - mana_ability_level_up: "\n Niveau de compétence de mana supérieur! {mana_ability} est maintenant niveau {level}" + ability_unlock: "\n Compétence débloquée! {ability} a été débloquée\n {desc}" + ability_level_up: "\n Niveau de compétence supérieur! {ability} est maintenant niveau {level}\n {desc}" + mana_ability_unlock: "\nCapacité de mana débloquée! {mana_ability} a été débloquée\n {desc}" + mana_ability_level_up: "\n Niveau de compétence de mana supérieur! {mana_ability} est maintenant niveau {level}\n {desc}" money_reward: "\n ${amount}" unclaimed_item: "Vous avez des objets non réclamés parce que votre inventaire était plein, utilisez /skills claimitems pour les réclamer" + desc_upgrade_value: "{current}→{next}" + desc_wrap: " " menus: common: close: "Fermer" @@ -1086,4 +1088,4 @@ units: mana: Mana hp: PV xp: XP -file_version: 30 +file_version: 31 diff --git a/common/src/main/java/dev/aurelium/auraskills/common/ability/AbilityUtil.java b/common/src/main/java/dev/aurelium/auraskills/common/ability/AbilityUtil.java new file mode 100644 index 000000000..fd5c5413c --- /dev/null +++ b/common/src/main/java/dev/aurelium/auraskills/common/ability/AbilityUtil.java @@ -0,0 +1,61 @@ +package dev.aurelium.auraskills.common.ability; + +import dev.aurelium.auraskills.api.ability.Ability; +import dev.aurelium.auraskills.api.mana.ManaAbilities; +import dev.aurelium.auraskills.api.mana.ManaAbility; +import dev.aurelium.auraskills.api.util.NumberUtil; +import dev.aurelium.auraskills.common.util.text.TextUtil; + +public class AbilityUtil { + + public static String getUpgradeValue(Ability ability, int level, String format) { + String currentValue = getCurrentValue(ability, level); + String nextValue = NumberUtil.format1(ability.getValue(level + 1)); + return TextUtil.replace(format, + "{current}", currentValue, + "{next}", nextValue); + } + + public static String getUpgradeValue2(Ability ability, int level, String format) { + String currentValue = getCurrentValue2(ability, level); + String nextValue = NumberUtil.format1(ability.getSecondaryValue(level + 1)); + return TextUtil.replace(format, + "{current}", currentValue, + "{next}", nextValue); + } + + public static String getCurrentValue(Ability ability, int level) { + return NumberUtil.format1(ability.getValue(level)); + } + + public static String getCurrentValue2(Ability ability, int level) { + return NumberUtil.format1(ability.getSecondaryValue(level)); + } + + public static String getUpgradeValue(ManaAbility manaAbility, int level, String format) { + String currentValue = NumberUtil.format1(manaAbility.getDisplayValue(level)); + String nextValue = NumberUtil.format1(manaAbility.getDisplayValue(level + 1)); + return TextUtil.replace(format, + "{current}", currentValue, + "{next}", nextValue); + } + + public static String getUpgradeDuration(ManaAbility manaAbility, int level, String format) { + String currentDuration = NumberUtil.format1(getDuration(manaAbility, level)); + String nextDuration = NumberUtil.format1(getDuration(manaAbility, level + 1)); + return TextUtil.replace(format, + "{current}", currentDuration, + "{next}", nextDuration); + } + + public static double getDuration(ManaAbility manaAbility, int level) { + if (manaAbility == ManaAbilities.LIGHTNING_BLADE) { + double baseDuration = ManaAbilities.LIGHTNING_BLADE.optionDouble("base_duration"); + double durationPerLevel = ManaAbilities.LIGHTNING_BLADE.optionDouble("duration_per_level"); + return baseDuration + (durationPerLevel * (level - 1)); + } else { + return manaAbility.getValue(level); + } + } + +} diff --git a/common/src/main/java/dev/aurelium/auraskills/common/level/LevelUpMessenger.java b/common/src/main/java/dev/aurelium/auraskills/common/level/LevelUpMessenger.java index 4528fc26c..ffcbfa71b 100644 --- a/common/src/main/java/dev/aurelium/auraskills/common/level/LevelUpMessenger.java +++ b/common/src/main/java/dev/aurelium/auraskills/common/level/LevelUpMessenger.java @@ -3,7 +3,9 @@ import dev.aurelium.auraskills.api.ability.Ability; import dev.aurelium.auraskills.api.mana.ManaAbility; import dev.aurelium.auraskills.api.skill.Skill; +import dev.aurelium.auraskills.api.util.NumberUtil; import dev.aurelium.auraskills.common.AuraSkillsPlugin; +import dev.aurelium.auraskills.common.ability.AbilityUtil; import dev.aurelium.auraskills.common.config.Option; import dev.aurelium.auraskills.common.message.MessageBuilder; import dev.aurelium.auraskills.common.message.type.LevelerMessage; @@ -11,6 +13,7 @@ import dev.aurelium.auraskills.common.reward.type.MoneyReward; import dev.aurelium.auraskills.common.user.User; import dev.aurelium.auraskills.common.util.math.RomanNumber; +import dev.aurelium.auraskills.common.util.text.TextUtil; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -19,6 +22,7 @@ public class LevelUpMessenger { + private static final int WRAP_LENGTH = 40; private final AuraSkillsPlugin plugin; private final User user; private final Locale locale; @@ -80,30 +84,48 @@ private String getAbilityUnlockMessage() { continue; } if (ability.getUnlock() == level) { // If ability is unlocked at this level + String desc = TextUtil.replace(ability.getDescription(locale), + "{value}", AbilityUtil.getCurrentValue(ability, 1), + "{value_2}", AbilityUtil.getCurrentValue2(ability, 1)); + desc = TextUtil.wrapText(desc, WRAP_LENGTH, "\n" + descWrap(locale)); builder.message(LevelerMessage.ABILITY_UNLOCK, - "ability", ability.getDisplayName(locale)); + "ability", ability.getDisplayName(locale), + "desc", desc); } } return builder.toString(); } private String getAbilityLevelUpMessage() { - MessageBuilder builder = MessageBuilder.create(plugin).locale(locale); + StringBuilder sb = new StringBuilder(); for (Ability ability : plugin.getAbilityManager().getAbilities(skill, level)) { if (!ability.isEnabled()) { continue; } if (ability.getUnlock() != level) { // If ability is unlocked at this level - builder.message(LevelerMessage.ABILITY_LEVEL_UP, - "ability", ability.getDisplayName(locale), - "level", RomanNumber.toRoman(user.getAbilityLevel(ability), plugin)); + int level = user.getAbilityLevel(ability); + sb.append(TextUtil.replace(plugin.getMsg(LevelerMessage.ABILITY_LEVEL_UP, locale), + "{ability}", ability.getDisplayName(locale), + "{previous}", RomanNumber.toRoman(level - 1, plugin), + "{level}", RomanNumber.toRoman(level, plugin), + "{desc}", getAbilityLevelUpDesc(ability, level, locale))); } } - return builder.toString(); + return sb.toString(); + } + + private String getAbilityLevelUpDesc(Ability ability, int level, Locale locale) { + String format = plugin.getMsg(LevelerMessage.DESC_UPGRADE_VALUE, locale); + // Subtract 1 from level to go from previous to current value + String desc = TextUtil.replace(ability.getDescription(locale), + "{value}", AbilityUtil.getUpgradeValue(ability, level - 1, format), + "{value_2}", AbilityUtil.getUpgradeValue2(ability, level - 1, format)); + desc = TextUtil.wrapText(desc, WRAP_LENGTH, "\n" + descWrap(locale)); + return com.archyx.polyglot.util.TextUtil.applyColor(desc); } private String getManaAbilityUnlockMessage() { - MessageBuilder builder = MessageBuilder.create(plugin).locale(locale); + StringBuilder sb = new StringBuilder(); ManaAbility manaAbility = plugin.getManaAbilityManager().getManaAbilityAtLevel(skill, level); if (manaAbility == null) return ""; @@ -111,14 +133,20 @@ private String getManaAbilityUnlockMessage() { // If mana ability is unlocked at this level if (manaAbility.getUnlock() == level) { - builder.message(LevelerMessage.MANA_ABILITY_UNLOCK, - "mana_ability", manaAbility.getDisplayName(locale)); + String desc = TextUtil.replace(manaAbility.getDescription(locale).replace("<1>", ""), + "{value}", String.valueOf(manaAbility.getDisplayValue(1)), + "{haste_level}", String.valueOf(manaAbility.optionInt("haste_level", 10)), + "{duration}", NumberUtil.format1(AbilityUtil.getDuration(manaAbility, 1))); + desc = TextUtil.wrapText(desc, WRAP_LENGTH, "\n" + descWrap(locale)); + sb.append(TextUtil.replace(plugin.getMsg(LevelerMessage.MANA_ABILITY_UNLOCK, locale), + "{mana_ability}", manaAbility.getDisplayName(locale), + "{desc}", desc)); } - return builder.toString(); + return com.archyx.polyglot.util.TextUtil.applyColor(sb.toString()); } private String getManaAbilityLevelUpMessage() { - MessageBuilder builder = MessageBuilder.create(plugin).locale(locale); + StringBuilder sb = new StringBuilder(); ManaAbility manaAbility = plugin.getManaAbilityManager().getManaAbilityAtLevel(skill, level); if (manaAbility == null) return ""; @@ -126,11 +154,25 @@ private String getManaAbilityLevelUpMessage() { // If mana ability is unlocked at this level if (manaAbility.getUnlock() != level) { - builder.message(LevelerMessage.MANA_ABILITY_LEVEL_UP, - "mana_ability", manaAbility.getDisplayName(locale), - "level", RomanNumber.toRoman(user.getManaAbilityLevel(manaAbility), plugin)); + int level = user.getManaAbilityLevel(manaAbility); + sb.append(TextUtil.replace(plugin.getMsg(LevelerMessage.MANA_ABILITY_LEVEL_UP, locale), + "{mana_ability}", manaAbility.getDisplayName(locale), + "{previous}", RomanNumber.toRoman(level - 1, plugin), + "{level}", RomanNumber.toRoman(level, plugin), + "{desc}", getManaAbilityLevelUpDesc(manaAbility, level, locale))); } - return builder.toString(); + return com.archyx.polyglot.util.TextUtil.applyColor(sb.toString()); + } + + private String getManaAbilityLevelUpDesc(ManaAbility manaAbility, int level, Locale locale) { + String format = plugin.getMsg(LevelerMessage.DESC_UPGRADE_VALUE, locale); + // Subtract 1 from level to go from previous to current value + String message = TextUtil.replace(manaAbility.getDescription(locale).replace("<1>", ""), + "{value}", AbilityUtil.getUpgradeValue(manaAbility, level - 1, format), + "{haste_level}", String.valueOf(manaAbility.optionInt("haste_level", 10)), + "{duration}", AbilityUtil.getUpgradeDuration(manaAbility, level - 1, format)); + message = TextUtil.wrapText(message, WRAP_LENGTH, "\n" + descWrap(locale)); + return message; } private String getMoneyRewardMessage() { @@ -148,4 +190,8 @@ private String getMoneyRewardMessage() { return builder.toString(); } + private String descWrap(Locale locale) { + return plugin.getMsg(LevelerMessage.DESC_WRAP, locale); + } + } diff --git a/common/src/main/java/dev/aurelium/auraskills/common/message/type/LevelerMessage.java b/common/src/main/java/dev/aurelium/auraskills/common/message/type/LevelerMessage.java index d168f7edd..b347cac2c 100644 --- a/common/src/main/java/dev/aurelium/auraskills/common/message/type/LevelerMessage.java +++ b/common/src/main/java/dev/aurelium/auraskills/common/message/type/LevelerMessage.java @@ -14,8 +14,10 @@ public enum LevelerMessage implements MessageKey { ABILITY_LEVEL_UP, MANA_ABILITY_UNLOCK, MANA_ABILITY_LEVEL_UP, + DESC_UPGRADE_VALUE, MONEY_REWARD, - UNCLAIMED_ITEM; + UNCLAIMED_ITEM, + DESC_WRAP; @Override public String getPath() { diff --git a/common/src/main/java/dev/aurelium/auraskills/common/util/text/TextUtil.java b/common/src/main/java/dev/aurelium/auraskills/common/util/text/TextUtil.java index 0af9d8792..ce002a3da 100644 --- a/common/src/main/java/dev/aurelium/auraskills/common/util/text/TextUtil.java +++ b/common/src/main/java/dev/aurelium/auraskills/common/util/text/TextUtil.java @@ -239,4 +239,78 @@ public static List getPlaceholders(String text) { return placeholders; } + public static String wrapText(String input, int maxLength, String insertion) { + StringBuilder sb = new StringBuilder(input); + + int i = 0; + List lines = new ArrayList<>(); + while (i < input.length()) { + String sub = substringIgnoreFormatting(sb.toString(), i, Math.min(i + maxLength, input.length())); + int addedLength = 0; + if (!sub.equals(" ")) { + String added = substringIgnoreFormatting(sub, 0, Math.min(maxLength, sub.length())); + int lastSpace = added.lastIndexOf(" "); + if (lastSpace != -1) { // Check if section contains spaces + if (sb.charAt(Math.min(i + added.length(), sb.length() - 1)) == ' ' || i + added.length() == sb.length()) { // Complete word or last word + lines.add(added); + addedLength = added.length(); + } else { // Cut off word + String addedCutOff = added.substring(0, lastSpace); + addedLength = addedCutOff.length(); + lines.add(addedCutOff); + } + } else { // Add the max number of characters and cut off word + lines.add(added); + addedLength = added.length(); + } + } + i = i + addedLength; + if (i < sb.length()) { + if (sb.charAt(i) == ' ') { + i++; + } + } + } + StringBuilder output = new StringBuilder(); + String lastInsertion = ""; + for (String line : lines) { + lastInsertion = insertion; + output.append(line).append(insertion); + } + output.replace(output.length() - lastInsertion.length(), output.length(), ""); + return output.toString(); + } + + private static String substringIgnoreFormatting(String input, int start, int end) { + if (input == null || input.isEmpty()) { + return ""; + } + if (start < 0 || end > input.length() || start > end) { + return ""; + } + StringBuilder result = new StringBuilder(); + boolean insideBrackets = false; + int count = 0; + for (int i = 0; i < input.length(); i++) { + char c = input.charAt(i); + if (c == '<') { + insideBrackets = true; + } + if (c == '>') { + insideBrackets = false; + } + if (!insideBrackets || count <= start) { + count++; + } + if (count > start && count <= end) { + result.append(c); + } + if (count > end) { + break; + } + } + + return result.toString(); + } + }