123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- package com.gmail.nossr50.config.experience;
- import com.gmail.nossr50.config.ConfigValidated;
- import com.gmail.nossr50.datatypes.experience.FormulaType;
- import com.gmail.nossr50.datatypes.skills.MaterialType;
- import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
- import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage;
- import com.gmail.nossr50.mcMMO;
- import com.gmail.nossr50.util.StringUtils;
- import org.bukkit.Material;
- import org.bukkit.boss.BarColor;
- import org.bukkit.boss.BarStyle;
- import org.bukkit.entity.EntityType;
- import java.util.ArrayList;
- import java.util.List;
- public class ExperienceConfig extends ConfigValidated {
- public static final String EXPLOIT_FIX = "ExploitFix";
- public static final String ENDERMAN_ENDERMITE_FARMS = "EndermanEndermiteFarms";
- public static final String EXPERIENCE = "Experience";
- public static final String EXPERIENCE_FORMULA = EXPERIENCE + "_Formula";
- public static final String CURVE = "Curve";
- public static final String VALUES = "_Values";
- public static final String MULTIPLIER = "multiplier";
- public static final String BASE = "base";
- public static final String EXPONENT = "exponent";
- public static final String MULTIPLIER1 = "Multiplier";
- public static final String GLOBAL = "Global";
- public static final String MOBSPAWNERS = "Mobspawners";
- public static final String BREEDING = "Breeding";
- public static final String MODIFIER = "Modifier";
- public static final String CUSTOM_XP_PERK = "Custom_XP_Perk";
- public static final String BOOST = "Boost";
- public static final String DIMISHED_RETURNS = "Dimished_Returns";
- public static final String GUARANTEED_MINIMUM_PERCENTAGE = "Guaranteed_Minimum_Percentage";
- public static final String DIMINISHED_RETURNS = "Diminished_Returns";
- public static final String ENABLE = "Enable";
- public static final String ENABLED = ENABLE + "d";
- public static final String TIME_INTERVAL = "Time_Interval";
- public static final String CONVERSION = "Conversion";
- public static final String EXP = "Exp_";
- public static final String PVP = "PVP";
- public static final String REWARDS = "Rewards";
- public static final String COMBAT = "Combat";
- public static final String ANIMALS = "Animals";
- public static final String BARS = "_Bars";
- public static final String UPDATE = "Update";
- public static final String PASSIVE = "Passive";
- public static final String THIS_MAY_CAUSE_LAG = "ThisMayCauseLag";
- public static final String ALWAYS = "Always";
- public static final String TITLES_WHEN_XPIS_GAINED = "TitlesWhenXPIsGained";
- public static final String EXTRA_DETAILS = "ExtraDetails";
- public static final String COLOR = "Color";
- public static final String BAR_STYLE = "BarStyle";
- public static final String ACROBATICS = "Acrobatics";
- public static final String DODGE = "Dodge";
- public static final String ROLL = "Roll";
- public static final String FALL = "Fall";
- public static final String FEATHER = "Feather";
- public static final String ALCHEMY = "Alchemy";
- public static final String POTION_STAGE = "Potion_Stage_";
- public static final String ARCHERY = "Archery";
- public static final String DISTANCE = "Distance_";
- public static final String FISHING = "Fishing";
- public static final String SHAKE = "Shake";
- public static final String REPAIR = "Repair";
- public static final String BASE1 = "Base";
- public static final String TAMING = "Taming";
- public static final String ANIMAL_TAMING = "Animal_Taming";
- public static final String PARTY = "Party";
- public static final String THRESHOLD = "Threshold";
- public static final String CUMULATIVE = "Cumulative_";
- public static final String OCELOT = "Ocelot";
- public static final String WOLF = "Wolf";
- public static final String FEATHER_FALL_MULTIPLIER = "FeatherFall_Multiplier";
- private static ExperienceConfig instance;
- //TODO: Should merge be false? Seems okay to leave it as true..
- private ExperienceConfig() {
- //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true);
- super(mcMMO.p.getDataFolder().getAbsoluteFile(), "experience.yml", true);
- }
- public static ExperienceConfig getInstance() {
- if (instance == null) {
- instance = new ExperienceConfig();
- }
- return instance;
- }
- /**
- * The version of this config
- *
- * @return
- */
- @Override
- public double getConfigVersion() {
- return 1;
- }
- @Override
- public void unload() {
- instance = null; //TODO: this might be a bit problematic
- }
- @Override
- public List<String> validateKeys() {
- List<String> reason = new ArrayList<String>();
- /*
- * 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 + "." + MULTIPLIER1 + "." + GLOBAL + " should be greater than 0!");
- }
- /* PVP modifier */
- if (getPlayerVersusPlayerXP() < 0) {
- reason.add(EXPERIENCE_FORMULA + "." + MULTIPLIER1 + "." + PVP + " should be at least 0!");
- }
- /* Spawned Mob modifier */
- if (getSpawnedMobXpMultiplier() < 0) {
- reason.add(EXPERIENCE_FORMULA + "." + MOBSPAWNERS + "." + MULTIPLIER1 + " should be at least 0!");
- }
- /* Bred Mob modifier */
- if (getBredMobXpMultiplier() < 0) {
- reason.add(EXPERIENCE_FORMULA + "." + BREEDING + "." + MULTIPLIER1 + " should be at least 0!");
- }
- /* Conversion */
- if (getExpModifier() <= 0) {
- reason.add(CONVERSION + "." + EXP + MODIFIER + " should be greater than 0!");
- }
- /*
- * XP SETTINGS
- */
- /* Alchemy */
- for (PotionStage potionStage : PotionStage.values()) {
- if (getPotionXP(potionStage) < 0) {
- reason.add(EXPERIENCE + "." + ALCHEMY + "." + POTION_STAGE + potionStage.toNumerical() + " should be at least 0!");
- }
- }
- /* Archery */
- if (getArcheryDistanceMultiplier() < 0) {
- reason.add(EXPERIENCE + "." + ARCHERY + "." + DISTANCE + MULTIPLIER1 + " should be at least 0!");
- }
- /* Combat XP Multipliers */
- if (getAnimalsXP() < 0) {
- reason.add(EXPERIENCE + "." + COMBAT + "." + MULTIPLIER1 + "." + ANIMALS + " should be at least 0!");
- }
- if (getDodgeXPModifier() < 0) {
- reason.add("Skills." + ACROBATICS + "." + DODGE + "_XP_" + MODIFIER + " should be at least 0!");
- }
- if (getRollXPModifier() < 0) {
- reason.add("Skills." + ACROBATICS + "." + ROLL + "_XP_" + MODIFIER + " should be at least 0!");
- }
- if (getFallXPModifier() < 0) {
- reason.add("Skills." + ACROBATICS + "." + FALL + "_XP_" + MODIFIER + " should be at least 0!");
- }
- /* Fishing */
- // TODO: Add validation for each fish type once enum is available.
- if (getFishingShakeXP() <= 0) {
- reason.add(EXPERIENCE + "." + FISHING + "." + SHAKE + " should be greater than 0!");
- }
- /* Repair */
- if (getRepairXPBase() <= 0) {
- reason.add(EXPERIENCE + "." + REPAIR + "." + BASE1 + " should be greater than 0!");
- }
- /* Taming */
- if (getTamingXP(EntityType.WOLF) <= 0) {
- reason.add(EXPERIENCE + "." + TAMING + "." + ANIMAL_TAMING + "." + WOLF + " should be greater than 0!");
- }
- if (getTamingXP(EntityType.OCELOT) <= 0) {
- reason.add(EXPERIENCE + "." + TAMING + "." + ANIMAL_TAMING + "." + OCELOT + " should be greater than 0!");
- }
- return reason;
- }
- /*
- * FORMULA SETTINGS
- */
- /* EXPLOIT TOGGLES */
- public boolean isEndermanEndermiteFarmingPrevented() {
- return getBooleanValue(EXPLOIT_FIX, ENDERMAN_ENDERMITE_FARMS);
- }
- public boolean isFishingExploitingPrevented() { return config.getBoolean("ExploitFix.Fishing", true); }
- /* Curve settings */
- public FormulaType getFormulaType() {
- return FormulaType.getFormulaType(getStringValue(EXPERIENCE_FORMULA, CURVE));
- }
- public boolean getCumulativeCurveEnabled() {
- 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, MULTIPLIER1, GLOBAL);
- }
- //TODO: Rewrite this
- /*public void setExperienceGainsGlobalMultiplier(double value) {
- config.set(EXPERIENCE_FORMULA, MULTIPLIER1, GLOBAL, value);
- }*/
- /* PVP modifier */
- public double getPlayerVersusPlayerXP() {
- return getDoubleValue(EXPERIENCE_FORMULA, MULTIPLIER1, PVP);
- }
- /* Spawned Mob modifier */
- public double getSpawnedMobXpMultiplier() {
- return getDoubleValue(EXPERIENCE_FORMULA, MOBSPAWNERS, MULTIPLIER1);
- }
- public double getBredMobXpMultiplier() {
- return getDoubleValue(EXPERIENCE_FORMULA, BREEDING, MULTIPLIER1);
- }
- /* Skill modifiers */
- public double getFormulaSkillModifier(PrimarySkillType skill) {
- return getDoubleValue(EXPERIENCE_FORMULA, MODIFIER, StringUtils.getCapitalized(skill.toString()));
- }
- /* Custom XP perk */
- public double getCustomXpPerkBoost() {
- return getDoubleValue(EXPERIENCE_FORMULA, CUSTOM_XP_PERK, BOOST);
- }
- /* Diminished Returns */
- public float getDiminishedReturnsCap() {
- return (float) getDoubleValue(DIMISHED_RETURNS, GUARANTEED_MINIMUM_PERCENTAGE);
- }
- public boolean getDiminishedReturnsEnabled() {
- return getBooleanValue(DIMINISHED_RETURNS, ENABLED);
- }
- public int getDiminishedReturnsThreshold(PrimarySkillType skill) {
- return getIntValue(DIMINISHED_RETURNS, THRESHOLD, StringUtils.getCapitalized(skill.toString()));
- }
- public int getDiminishedReturnsTimeInterval() {
- return getIntValue(DIMINISHED_RETURNS, TIME_INTERVAL);
- }
- /* Conversion */
- public double getExpModifier() {
- return getDoubleValue(CONVERSION, EXP + MODIFIER);
- }
- /*
- * XP SETTINGS
- */
- /* General Settings */
- public boolean getExperienceGainsPlayerVersusPlayerEnabled() {
- return getBooleanValue(EXPERIENCE, PVP, REWARDS);
- }
- /* Combat XP Multipliers */
- public double getCombatXP(EntityType entity) {
- return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, StringUtils.getEntityConfigName(entity));
- }
- public double getAnimalsXP(EntityType entity) {
- return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, StringUtils.getEntityConfigName(entity));
- }
- public double getAnimalsXP() {
- return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, ANIMALS);
- }
- public boolean hasCombatXP(EntityType entity) {
- return hasNode(EXPERIENCE, COMBAT, MULTIPLIER1, StringUtils.getEntityConfigName(entity));
- }
- /* Materials */
- /**
- * Gets the raw XP given for breaking this block, this does not include modifiers
- * @param skill The skill to give XP for
- * @param blockType the type of block
- * @return the raw amount of XP for this block before modifiers
- */
- //public int getXp(PrimarySkillType skill, BlockType blockType) {
- public int getXp(PrimarySkillType skill, Material blockType) {
- //TODO: This is going to need to be changed, this code here is only placeholder
- String[] path = new String[]{ EXPERIENCE, StringUtils.getCapitalized(skill.toString()), blockType.toString()};
- return getIntValue(path);
- }
- /**
- * Checks if a block gives XP
- * This is used to determine whether or not mcMMO should track a block that is placed by a user, among other things.
- * Note: If the block has an entry in the config that will return true even if the XP is 0, this does not check the value of the XP
- * @param skill The skill to check for
- * @param blockType the type of block
- * @return true if the block does give XP
- */
- public boolean doesBlockGiveSkillXP(PrimarySkillType skill, Material blockType) {
- //TODO: This used to support wildcard characters, seems a bit unnecessary to do so.
- //TODO: This is going to need to be changed, this code here is only placeholder
- String[] path = new String[] {EXPERIENCE, StringUtils.getCapitalized(skill.toString()), blockType.toString()};
- return hasNode(path);
- }
- /*
- * Experience Bar Stuff
- */
- public boolean isPartyExperienceBarsEnabled() {
- return getBooleanValue(EXPERIENCE + BARS, UPDATE, PARTY);
- }
- public boolean isPassiveGainsExperienceBarsEnabled() {
- return getBooleanValue(EXPERIENCE + BARS, UPDATE, PASSIVE);
- }
- public boolean getDoExperienceBarsAlwaysUpdateTitle() {
- return getBooleanValue(EXPERIENCE + BARS, THIS_MAY_CAUSE_LAG, ALWAYS + UPDATE + TITLES_WHEN_XPIS_GAINED, ENABLE) || getAddExtraDetails();
- }
- public boolean getAddExtraDetails() {
- return getBooleanValue(EXPERIENCE + BARS, THIS_MAY_CAUSE_LAG, ALWAYS + UPDATE + TITLES_WHEN_XPIS_GAINED, EXTRA_DETAILS);
- }
- public boolean isExperienceBarsEnabled() {
- return getBooleanValue(EXPERIENCE + BARS, ENABLE);
- }
- public boolean isExperienceBarEnabled(PrimarySkillType primarySkillType) {
- return getBooleanValue(EXPERIENCE + BARS, StringUtils.getCapitalized(primarySkillType.toString()), ENABLE);
- }
- public BarColor getExperienceBarColor(PrimarySkillType primarySkillType) {
- String colorValueFromConfig = getStringValue(EXPERIENCE + BARS, StringUtils.getCapitalized(primarySkillType.toString()), COLOR);
- for (BarColor barColor : BarColor.values()) {
- if (barColor.toString().equalsIgnoreCase(colorValueFromConfig))
- return barColor;
- }
- //In case the value is invalid
- return BarColor.WHITE;
- }
- public BarStyle getExperienceBarStyle(PrimarySkillType primarySkillType) {
- String colorValueFromConfig = getStringValue(EXPERIENCE + BARS, StringUtils.getCapitalized(primarySkillType.toString()), BAR_STYLE);
- for (BarStyle barStyle : BarStyle.values()) {
- if (barStyle.toString().equalsIgnoreCase(colorValueFromConfig))
- return barStyle;
- }
- //In case the value is invalid
- return BarStyle.SOLID;
- }
- /* Acrobatics */
- public int getDodgeXPModifier() {
- return getIntValue(EXPERIENCE, ACROBATICS, DODGE);
- }
- public int getRollXPModifier() {
- return getIntValue(EXPERIENCE, ACROBATICS, ROLL);
- }
- public int getFallXPModifier() {
- return getIntValue(EXPERIENCE, ACROBATICS, FALL);
- }
- public double getFeatherFallXPModifier() {
- return getDoubleValue(EXPERIENCE, ACROBATICS, FEATHER_FALL_MULTIPLIER);
- }
- /* Alchemy */
- public double getPotionXP(PotionStage stage) {
- return getDoubleValue(EXPERIENCE, ALCHEMY, POTION_STAGE + stage.toNumerical());
- }
- /* Archery */
- public double getArcheryDistanceMultiplier() {
- return getDoubleValue(EXPERIENCE, ARCHERY, DISTANCE + MULTIPLIER1);
- }
- public int getFishingShakeXP() {
- return getIntValue(EXPERIENCE, FISHING, SHAKE);
- }
- /* Repair */
- public double getRepairXPBase() {
- return getDoubleValue(EXPERIENCE, REPAIR, BASE1);
- }
- public double getRepairXP(MaterialType repairMaterialType) {
- return getDoubleValue(EXPERIENCE, REPAIR, StringUtils.getCapitalized(repairMaterialType.toString()));
- }
- /* Taming */
- public int getTamingXP(EntityType type) {
- return getIntValue(EXPERIENCE, TAMING, ANIMAL_TAMING, StringUtils.getEntityConfigName(type));
- }
- }
|