From dc758a6dfc2cf352c38f3eb165154673b059bf89 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 24 Apr 2019 22:44:24 -0700 Subject: [PATCH] Wire up XP formula settings --- .../config/experience/ExperienceConfig.java | 27 ------------------- .../ConfigExperienceFormula.java | 26 ++++++++++++++++++ .../ConfigExperienceFormulaExponential.java | 9 +++---- .../ConfigExperienceFormulaLinear.java | 6 ++--- .../hocon/playerleveling/ConfigLeveling.java | 12 +++++++++ .../ConfigSectionLevelingGeneral.java | 1 - .../IncorrectFormulaException.java | 11 ++++++++ .../gmail/nossr50/datatypes/party/Party.java | 2 -- .../skills/McMMOPlayerNotificationEvent.java | 1 - src/main/java/com/gmail/nossr50/mcMMO.java | 5 +--- .../util/experience/FormulaManager.java | 13 +++++---- .../nossr50/util/player/UserManager.java | 1 - 12 files changed, 61 insertions(+), 53 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/playerleveling/IncorrectFormulaException.java diff --git a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java index 96227e87b..9309a97ac 100644 --- a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java +++ b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.config.experience; import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.config.ConfigValidated; -import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.skills.ItemMaterialCategory; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; @@ -119,19 +118,6 @@ public class ExperienceConfig extends ConfigValidated { * FORMULA SETTINGS */ - /* Curve values */ - if (getMultiplier(FormulaType.EXPONENTIAL) <= 0) { - reason.add(EXPERIENCE_FORMULA + ".Exponential" + VALUES + "." + MULTIPLIER + " should be greater than 0!"); - } - - if (getMultiplier(FormulaType.LINEAR) <= 0) { - reason.add(EXPERIENCE_FORMULA + ".Linear" + VALUES + "." + MULTIPLIER + " should be greater than 0!"); - } - - if (getExponent(FormulaType.EXPONENTIAL) <= 0) { - reason.add(EXPERIENCE_FORMULA + ".Exponential" + VALUES + "." + EXPONENT + " should be greater than 0!"); - } - /* Global modifier */ if (getExperienceGainsGlobalMultiplier() <= 0) { reason.add(EXPERIENCE_FORMULA + "." + MULTIPLIER + "." + GLOBAL + " should be greater than 0!"); @@ -194,19 +180,6 @@ public class ExperienceConfig extends ConfigValidated { return getBooleanValue(EXPERIENCE_FORMULA, CUMULATIVE + CURVE); } - /* Curve values */ - public double getMultiplier(FormulaType type) { - return getDoubleValue(EXPERIENCE_FORMULA, StringUtils.getCapitalized(type.toString()) + VALUES, MULTIPLIER); - } - - public int getBase(FormulaType type) { - return getIntValue(EXPERIENCE_FORMULA, StringUtils.getCapitalized(type.toString()) + VALUES, BASE); - } - - public double getExponent(FormulaType type) { - return getDoubleValue(EXPERIENCE_FORMULA, StringUtils.getCapitalized(type.toString()) + VALUES, EXPONENT); - } - /* Global modifier */ public double getExperienceGainsGlobalMultiplier() { return getDoubleValue(EXPERIENCE_FORMULA, MULTIPLIER, GLOBAL); diff --git a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormula.java b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormula.java index bda672b34..43cbcc83a 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormula.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormula.java @@ -31,6 +31,32 @@ public class ConfigExperienceFormula { return configExperienceFormulaExponential; } + public double getMultiplier(FormulaType formulaType) + { + switch(formulaType) + { + case LINEAR: + return getLinearMultiplier(); + case EXPONENTIAL: + return getExponentialMultiplier(); + default: + throw new IncorrectFormulaException(formulaType); + } + } + + public int getBase(FormulaType formulaType) + { + switch(formulaType) + { + case LINEAR: + return getLinearBaseModifier(); + case EXPONENTIAL: + return getExponentialBaseModifier(); + default: + throw new IncorrectFormulaException(formulaType); + } + } + public int getExponentialBaseModifier() { return configExperienceFormulaExponential.getExponentialBaseModifier(); } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaExponential.java b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaExponential.java index f89f7dc62..97ff833a9 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaExponential.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaExponential.java @@ -10,16 +10,13 @@ public class ConfigExperienceFormulaExponential { private static final double MULTIPLIER_DEFAULT = 0.1; private static final double EXPONENT_DEFAULT = 1.80; - @Setting(value = "Base-Amount", comment = "" + - "\nDefault value: "+BASE_DEFAULT) + @Setting(value = "Base-Amount", comment = "Default value: "+BASE_DEFAULT) private int baseModifier = BASE_DEFAULT; - @Setting(value = "Multiplier", comment = "" + - "\nDefault value: "+MULTIPLIER_DEFAULT) + @Setting(value = "Multiplier", comment = "Default value: "+MULTIPLIER_DEFAULT) private double multiplier = MULTIPLIER_DEFAULT; - @Setting(value = "Exponent", comment = "" + - "\nDefault value: "+EXPONENT_DEFAULT) + @Setting(value = "Exponent", comment = "Default value: "+EXPONENT_DEFAULT) private double exponent = EXPONENT_DEFAULT; public int getExponentialBaseModifier() { diff --git a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaLinear.java b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaLinear.java index 6f978ad30..1d88c7fbd 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaLinear.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaLinear.java @@ -9,12 +9,10 @@ public class ConfigExperienceFormulaLinear { private static final int BASE_DEFAULT = 1020; private static final double MULTIPLIER_DEFAULT = 20.0D; - @Setting(value = "Base-Amount", comment = "The formula for Linear adds the base amount without any modifications to the level requirement for every level." + - "\nDefault value: "+BASE_DEFAULT) + @Setting(value = "Base-Amount", comment = "Default value: "+BASE_DEFAULT) private int baseModifier = BASE_DEFAULT; - @Setting(value = "Multiplier", comment = "The multiplier is multiplied against the players level and then added to the base amount to determine the amount of XP to the next level" + - "\nDefault value: "+MULTIPLIER_DEFAULT) + @Setting(value = "Multiplier", comment = "Default value: "+MULTIPLIER_DEFAULT) private double multiplier = MULTIPLIER_DEFAULT; public int getLinearBaseModifier() { diff --git a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigLeveling.java b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigLeveling.java index 29b0dd3fc..af18686fa 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigLeveling.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigLeveling.java @@ -43,6 +43,10 @@ public class ConfigLeveling { return configSectionLevelingGeneral.getConfigSectionLevelScaling(); } + public ConfigExperienceFormula getConfigExperienceFormula() { + return configExperienceFormula; + } + public FormulaType getFormulaType() { return configExperienceFormula.getFormulaType(); } @@ -59,6 +63,14 @@ public class ConfigLeveling { return configExperienceFormula.getConfigExperienceFormulaExponential(); } + public int getBase(FormulaType formulaType) { + return configExperienceFormula.getBase(formulaType); + } + + public double getMultiplier(FormulaType formulaType) { + return configExperienceFormula.getMultiplier(formulaType); + } + public int getExponentialBaseModifier() { return configExperienceFormula.getExponentialBaseModifier(); } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigSectionLevelingGeneral.java b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigSectionLevelingGeneral.java index 4e861278d..e951f6878 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigSectionLevelingGeneral.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigSectionLevelingGeneral.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.config.hocon.playerleveling; -import com.gmail.nossr50.datatypes.experience.FormulaType; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/IncorrectFormulaException.java b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/IncorrectFormulaException.java new file mode 100644 index 000000000..f56a4af90 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/IncorrectFormulaException.java @@ -0,0 +1,11 @@ +package com.gmail.nossr50.config.hocon.playerleveling; + +import com.gmail.nossr50.datatypes.experience.FormulaType; + +public class IncorrectFormulaException extends RuntimeException { + + public IncorrectFormulaException(FormulaType formulaType) { + super("Formula not recognized: " + formulaType.toString()); + } + +} diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java index 771e60d7d..78120e804 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java @@ -1,8 +1,6 @@ package com.gmail.nossr50.datatypes.party; import com.gmail.nossr50.config.MainConfig; -import com.gmail.nossr50.config.experience.ExperienceConfig; -import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; diff --git a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerNotificationEvent.java b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerNotificationEvent.java index 59114fc28..05ed0f510 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerNotificationEvent.java +++ b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerNotificationEvent.java @@ -7,7 +7,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; /** * This event is sent for when mcMMO informs a player about various important information diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 8b4ed02d1..4d21c4d08 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -45,13 +45,10 @@ import org.bukkit.event.HandlerList; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; + import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; public class mcMMO extends JavaPlugin { public static final String COMPATIBLE_SERVER_SOFTWARE = "Spigot, Paper"; diff --git a/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java b/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java index a8383c687..abb85e8f3 100644 --- a/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java +++ b/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.util.experience; -import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; @@ -130,9 +129,9 @@ public class FormulaManager { formulaType = FormulaType.LINEAR; } - int base = ExperienceConfig.getInstance().getBase(formulaType); - double multiplier = ExperienceConfig.getInstance().getMultiplier(formulaType); - double exponent = ExperienceConfig.getInstance().getExponent(formulaType); + int base = mcMMO.getConfigManager().getConfigLeveling().getBase(formulaType); + double multiplier = mcMMO.getConfigManager().getConfigLeveling().getMultiplier(formulaType); + double exponent = mcMMO.getConfigManager().getConfigLeveling().getExponentialExponent(); switch (formulaType) { case LINEAR: @@ -173,9 +172,9 @@ public class FormulaManager { * Retro mode XP requirements are the default requirements * Standard mode XP requirements are multiplied by a factor of 10 */ - int base = ExperienceConfig.getInstance().getBase(FormulaType.EXPONENTIAL); - double multiplier = ExperienceConfig.getInstance().getMultiplier(FormulaType.EXPONENTIAL); - double exponent = ExperienceConfig.getInstance().getExponent(FormulaType.EXPONENTIAL); + int base = mcMMO.getConfigManager().getConfigLeveling().getBase(FormulaType.EXPONENTIAL); + double multiplier = mcMMO.getConfigManager().getConfigLeveling().getMultiplier(FormulaType.EXPONENTIAL); + double exponent = mcMMO.getConfigManager().getConfigLeveling().getExponentialExponent(); if (!experienceNeededExponential.containsKey(level)) { experience = (int) Math.floor((multiplier * Math.pow(level, exponent) + base)); diff --git a/src/main/java/com/gmail/nossr50/util/player/UserManager.java b/src/main/java/com/gmail/nossr50/util/player/UserManager.java index d7e5ab4ab..73f3b16cc 100644 --- a/src/main/java/com/gmail/nossr50/util/player/UserManager.java +++ b/src/main/java/com/gmail/nossr50/util/player/UserManager.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.util.player; -import com.gmail.nossr50.api.exceptions.McMMOPlayerNotFoundException; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.mcMMO; import com.google.common.collect.ImmutableList;