From 49b699b54bbb8d2864ac42a7e6b68f9c9b052220 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 25 Jun 2023 15:13:04 +0100 Subject: [PATCH] Added possibility to specify decimal format for each skill parameter regarding issue #866. --- .../net/Indyuce/mmocore/skill/ClassSkill.java | 5 ++++- .../Indyuce/mmocore/skill/RegisteredSkill.java | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java index 203a10c6..6f8ee174 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java @@ -149,7 +149,10 @@ public class ClassSkill implements CooldownObject, Unlockable { // Calculate placeholders Placeholders placeholders = new Placeholders(); - parameters.keySet().forEach(modifier -> placeholders.register(modifier, MythicLib.plugin.getMMOConfig().decimal.format(data.getMMOPlayerData().getSkillModifierMap().getInstance(skill.getHandler(), modifier).getTotal(parameters.get(modifier).calculate(x))))); + parameters.keySet() + .forEach(param -> { + placeholders.register(param, skill.getDecimalFormat(param).format(data.getMMOPlayerData().getSkillModifierMap().getInstance(skill.getHandler(), param).getTotal(parameters.get(param).calculate(x)))); + }); placeholders.register("mana_name", data.getProfess().getManaDisplay().getName()); placeholders.register("mana_color", data.getProfess().getManaDisplay().getFull().toString()); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java index 2affad11..589b97eb 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java @@ -13,12 +13,16 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.text.DecimalFormat; import java.util.*; public class RegisteredSkill { private final SkillHandler handler; private final String name; private final Map defaultParameters = new HashMap<>(); + + private final Map parameterDecimalFormats = new HashMap<>(); + private final ItemStack icon; private final List lore; private final List categories; @@ -42,10 +46,15 @@ public class RegisteredSkill { else categories.add("ACTIVE"); + // Load default modifier formulas - for (String param : handler.getParameters()) + for (String param : handler.getParameters()) { + if (config.contains(param + ".decimal-format")) + parameterDecimalFormats.put(param, new DecimalFormat(config.getString(param + ".decimal-format"))); defaultParameters.put(param, config.contains(param) ? new LinearValue(config.getConfigurationSection(param)) : LinearValue.ZERO); + } + /* * This is so that SkillAPI skill level matches the MMOCore skill level * https://gitlab.com/phoenix-dvpmt/mmocore/-/issues/531 @@ -111,6 +120,10 @@ public class RegisteredSkill { defaultParameters.put(parameter, linear); } + public DecimalFormat getDecimalFormat(String parameter) { + return parameterDecimalFormats.getOrDefault(parameter, MythicLib.plugin.getMMOConfig().decimal); + } + @Deprecated public void addModifierIfNone(String mod, LinearValue defaultValue) {