mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 11:03:43 +01:00 
			
		
		
		
	Wire up XP formula settings
This commit is contained in:
		@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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() {
 | 
			
		||||
 
 | 
			
		||||
@@ -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() {
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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";
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user