ExperienceConfig.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. package com.gmail.nossr50.config.experience;
  2. import com.gmail.nossr50.config.ConfigValidated;
  3. import com.gmail.nossr50.config.MainConfig;
  4. import com.gmail.nossr50.datatypes.experience.FormulaType;
  5. import com.gmail.nossr50.datatypes.skills.MaterialType;
  6. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  7. import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage;
  8. import com.gmail.nossr50.mcMMO;
  9. import com.gmail.nossr50.util.StringUtils;
  10. import org.bukkit.Material;
  11. import org.bukkit.boss.BarColor;
  12. import org.bukkit.boss.BarStyle;
  13. import org.bukkit.entity.EntityType;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. public class ExperienceConfig extends ConfigValidated {
  17. public static final String EXPLOIT_FIX = "ExploitFix";
  18. public static final String ENDERMAN_ENDERMITE_FARMS = "EndermanEndermiteFarms";
  19. public static final String EXPERIENCE = "Experience";
  20. public static final String EXPERIENCE_FORMULA = EXPERIENCE + "_Formula";
  21. public static final String CURVE = "Curve";
  22. public static final String VALUES = "_Values";
  23. public static final String MULTIPLIER = "multiplier";
  24. public static final String BASE = "base";
  25. public static final String EXPONENT = "exponent";
  26. public static final String MULTIPLIER1 = "Multiplier";
  27. public static final String GLOBAL = "Global";
  28. public static final String MOBSPAWNERS = "Mobspawners";
  29. public static final String BREEDING = "Breeding";
  30. public static final String MODIFIER = "Modifier";
  31. public static final String CUSTOM_XP_PERK = "Custom_XP_Perk";
  32. public static final String BOOST = "Boost";
  33. public static final String DIMISHED_RETURNS = "Dimished_Returns";
  34. public static final String GUARANTEED_MINIMUM_PERCENTAGE = "Guaranteed_Minimum_Percentage";
  35. public static final String DIMINISHED_RETURNS = "Diminished_Returns";
  36. public static final String ENABLE = "Enable";
  37. public static final String ENABLED = ENABLE + "d";
  38. public static final String TIME_INTERVAL = "Time_Interval";
  39. public static final String CONVERSION = "Conversion";
  40. public static final String EXP = "Exp_";
  41. public static final String PVP = "PVP";
  42. public static final String REWARDS = "Rewards";
  43. public static final String COMBAT = "Combat";
  44. public static final String ANIMALS = "Animals";
  45. public static final String BARS = "_Bars";
  46. public static final String UPDATE = "Update";
  47. public static final String PASSIVE = "Passive";
  48. public static final String THIS_MAY_CAUSE_LAG = "ThisMayCauseLag";
  49. public static final String ALWAYS = "Always";
  50. public static final String TITLES_WHEN_XPIS_GAINED = "TitlesWhenXPIsGained";
  51. public static final String EXTRA_DETAILS = "ExtraDetails";
  52. public static final String COLOR = "Color";
  53. public static final String BAR_STYLE = "BarStyle";
  54. public static final String ACROBATICS = "Acrobatics";
  55. public static final String DODGE = "Dodge";
  56. public static final String ROLL = "Roll";
  57. public static final String FALL = "Fall";
  58. public static final String FEATHER = "Feather";
  59. public static final String ALCHEMY = "Alchemy";
  60. public static final String POTION_STAGE = "Potion_Stage_";
  61. public static final String ARCHERY = "Archery";
  62. public static final String DISTANCE = "Distance_";
  63. public static final String FISHING = "Fishing";
  64. public static final String SHAKE = "Shake";
  65. public static final String REPAIR = "Repair";
  66. public static final String BASE1 = "Base";
  67. public static final String TAMING = "Taming";
  68. public static final String ANIMAL_TAMING = "Animal_Taming";
  69. public static final String PARTY = "Party";
  70. public static final String THRESHOLD = "Threshold";
  71. public static final String CUMULATIVE = "Cumulative_";
  72. public static final String OCELOT = "Ocelot";
  73. public static final String WOLF = "Wolf";
  74. public static final String FEATHER_FALL_MULTIPLIER = "FeatherFall_Multiplier";
  75. private static ExperienceConfig instance;
  76. //TODO: Should merge be false? Seems okay to leave it as true..
  77. public ExperienceConfig() {
  78. //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true);
  79. super(mcMMO.p.getDataFolder().getAbsoluteFile(), "experience.yml", true);
  80. }
  81. /**
  82. * This grabs an instance of this config class from the Config Manager
  83. * This method is deprecated and will be removed in the future
  84. * @see mcMMO#getConfigManager()
  85. * @return the instance of this config
  86. * @deprecated Please use mcMMO.getConfigManager() to grab a specific config instead
  87. */
  88. @Deprecated
  89. public static ExperienceConfig getInstance() {
  90. return mcMMO.getConfigManager()
  91. }
  92. /**
  93. * The version of this config
  94. *
  95. * @return
  96. */
  97. @Override
  98. public double getConfigVersion() {
  99. return 1;
  100. }
  101. @Override
  102. public void unload() {
  103. instance = null; //TODO: this might be a bit problematic
  104. }
  105. @Override
  106. public List<String> validateKeys() {
  107. List<String> reason = new ArrayList<String>();
  108. /*
  109. * FORMULA SETTINGS
  110. */
  111. /* Curve values */
  112. if (getMultiplier(FormulaType.EXPONENTIAL) <= 0) {
  113. reason.add(EXPERIENCE_FORMULA + ".Exponential" + VALUES + "." + MULTIPLIER + " should be greater than 0!");
  114. }
  115. if (getMultiplier(FormulaType.LINEAR) <= 0) {
  116. reason.add(EXPERIENCE_FORMULA + ".Linear" + VALUES + "." + MULTIPLIER + " should be greater than 0!");
  117. }
  118. if (getExponent(FormulaType.EXPONENTIAL) <= 0) {
  119. reason.add(EXPERIENCE_FORMULA + ".Exponential" + VALUES + "." + EXPONENT + " should be greater than 0!");
  120. }
  121. /* Global modifier */
  122. if (getExperienceGainsGlobalMultiplier() <= 0) {
  123. reason.add(EXPERIENCE_FORMULA + "." + MULTIPLIER1 + "." + GLOBAL + " should be greater than 0!");
  124. }
  125. /* PVP modifier */
  126. if (getPlayerVersusPlayerXP() < 0) {
  127. reason.add(EXPERIENCE_FORMULA + "." + MULTIPLIER1 + "." + PVP + " should be at least 0!");
  128. }
  129. /* Spawned Mob modifier */
  130. if (getSpawnedMobXpMultiplier() < 0) {
  131. reason.add(EXPERIENCE_FORMULA + "." + MOBSPAWNERS + "." + MULTIPLIER1 + " should be at least 0!");
  132. }
  133. /* Bred Mob modifier */
  134. if (getBredMobXpMultiplier() < 0) {
  135. reason.add(EXPERIENCE_FORMULA + "." + BREEDING + "." + MULTIPLIER1 + " should be at least 0!");
  136. }
  137. /* Conversion */
  138. if (getExpModifier() <= 0) {
  139. reason.add(CONVERSION + "." + EXP + MODIFIER + " should be greater than 0!");
  140. }
  141. /*
  142. * XP SETTINGS
  143. */
  144. /* Alchemy */
  145. for (PotionStage potionStage : PotionStage.values()) {
  146. if (getPotionXP(potionStage) < 0) {
  147. reason.add(EXPERIENCE + "." + ALCHEMY + "." + POTION_STAGE + potionStage.toNumerical() + " should be at least 0!");
  148. }
  149. }
  150. /* Archery */
  151. if (getArcheryDistanceMultiplier() < 0) {
  152. reason.add(EXPERIENCE + "." + ARCHERY + "." + DISTANCE + MULTIPLIER1 + " should be at least 0!");
  153. }
  154. /* Combat XP Multipliers */
  155. if (getAnimalsXP() < 0) {
  156. reason.add(EXPERIENCE + "." + COMBAT + "." + MULTIPLIER1 + "." + ANIMALS + " should be at least 0!");
  157. }
  158. if (getDodgeXPModifier() < 0) {
  159. reason.add("Skills." + ACROBATICS + "." + DODGE + "_XP_" + MODIFIER + " should be at least 0!");
  160. }
  161. if (getRollXPModifier() < 0) {
  162. reason.add("Skills." + ACROBATICS + "." + ROLL + "_XP_" + MODIFIER + " should be at least 0!");
  163. }
  164. if (getFallXPModifier() < 0) {
  165. reason.add("Skills." + ACROBATICS + "." + FALL + "_XP_" + MODIFIER + " should be at least 0!");
  166. }
  167. /* Fishing */
  168. // TODO: Add validation for each fish type once enum is available.
  169. if (getFishingShakeXP() <= 0) {
  170. reason.add(EXPERIENCE + "." + FISHING + "." + SHAKE + " should be greater than 0!");
  171. }
  172. /* Repair */
  173. if (getRepairXPBase() <= 0) {
  174. reason.add(EXPERIENCE + "." + REPAIR + "." + BASE1 + " should be greater than 0!");
  175. }
  176. /* Taming */
  177. if (getTamingXP(EntityType.WOLF) <= 0) {
  178. reason.add(EXPERIENCE + "." + TAMING + "." + ANIMAL_TAMING + "." + WOLF + " should be greater than 0!");
  179. }
  180. if (getTamingXP(EntityType.OCELOT) <= 0) {
  181. reason.add(EXPERIENCE + "." + TAMING + "." + ANIMAL_TAMING + "." + OCELOT + " should be greater than 0!");
  182. }
  183. return reason;
  184. }
  185. /*
  186. * FORMULA SETTINGS
  187. */
  188. /* EXPLOIT TOGGLES */
  189. public boolean isEndermanEndermiteFarmingPrevented() {
  190. return getBooleanValue(EXPLOIT_FIX, ENDERMAN_ENDERMITE_FARMS);
  191. }
  192. public boolean isFishingExploitingPrevented() { return config.getBoolean("ExploitFix.Fishing", true); }
  193. /* Curve settings */
  194. public FormulaType getFormulaType() {
  195. return FormulaType.getFormulaType(getStringValue(EXPERIENCE_FORMULA, CURVE));
  196. }
  197. public boolean getCumulativeCurveEnabled() {
  198. return getBooleanValue(EXPERIENCE_FORMULA, CUMULATIVE + CURVE);
  199. }
  200. /* Curve values */
  201. public double getMultiplier(FormulaType type) {
  202. return getDoubleValue(EXPERIENCE_FORMULA, StringUtils.getCapitalized(type.toString()) + VALUES, MULTIPLIER);
  203. }
  204. public int getBase(FormulaType type) {
  205. return getIntValue(EXPERIENCE_FORMULA, StringUtils.getCapitalized(type.toString()) + VALUES, BASE);
  206. }
  207. public double getExponent(FormulaType type) {
  208. return getDoubleValue(EXPERIENCE_FORMULA, StringUtils.getCapitalized(type.toString()) + VALUES, EXPONENT);
  209. }
  210. /* Global modifier */
  211. public double getExperienceGainsGlobalMultiplier() {
  212. return getDoubleValue(EXPERIENCE_FORMULA, MULTIPLIER1, GLOBAL);
  213. }
  214. //TODO: Rewrite this
  215. /*public void setExperienceGainsGlobalMultiplier(double value) {
  216. config.set(EXPERIENCE_FORMULA, MULTIPLIER1, GLOBAL, value);
  217. }*/
  218. /* PVP modifier */
  219. public double getPlayerVersusPlayerXP() {
  220. return getDoubleValue(EXPERIENCE_FORMULA, MULTIPLIER1, PVP);
  221. }
  222. /* Spawned Mob modifier */
  223. public double getSpawnedMobXpMultiplier() {
  224. return getDoubleValue(EXPERIENCE_FORMULA, MOBSPAWNERS, MULTIPLIER1);
  225. }
  226. public double getBredMobXpMultiplier() {
  227. return getDoubleValue(EXPERIENCE_FORMULA, BREEDING, MULTIPLIER1);
  228. }
  229. /* Skill modifiers */
  230. public double getFormulaSkillModifier(PrimarySkillType skill) {
  231. return getDoubleValue(EXPERIENCE_FORMULA, MODIFIER, StringUtils.getCapitalized(skill.toString()));
  232. }
  233. /* Custom XP perk */
  234. public double getCustomXpPerkBoost() {
  235. return getDoubleValue(EXPERIENCE_FORMULA, CUSTOM_XP_PERK, BOOST);
  236. }
  237. /* Diminished Returns */
  238. public float getDiminishedReturnsCap() {
  239. return (float) getDoubleValue(DIMISHED_RETURNS, GUARANTEED_MINIMUM_PERCENTAGE);
  240. }
  241. public boolean getDiminishedReturnsEnabled() {
  242. return getBooleanValue(DIMINISHED_RETURNS, ENABLED);
  243. }
  244. public int getDiminishedReturnsThreshold(PrimarySkillType skill) {
  245. return getIntValue(DIMINISHED_RETURNS, THRESHOLD, StringUtils.getCapitalized(skill.toString()));
  246. }
  247. public int getDiminishedReturnsTimeInterval() {
  248. return getIntValue(DIMINISHED_RETURNS, TIME_INTERVAL);
  249. }
  250. /* Conversion */
  251. public double getExpModifier() {
  252. return getDoubleValue(CONVERSION, EXP + MODIFIER);
  253. }
  254. /*
  255. * XP SETTINGS
  256. */
  257. /* General Settings */
  258. public boolean getExperienceGainsPlayerVersusPlayerEnabled() {
  259. return getBooleanValue(EXPERIENCE, PVP, REWARDS);
  260. }
  261. /* Combat XP Multipliers */
  262. public double getCombatXP(EntityType entity) {
  263. return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, StringUtils.getEntityConfigName(entity));
  264. }
  265. public double getAnimalsXP(EntityType entity) {
  266. return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, StringUtils.getEntityConfigName(entity));
  267. }
  268. public double getAnimalsXP() {
  269. return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, ANIMALS);
  270. }
  271. public boolean hasCombatXP(EntityType entity) {
  272. return hasNode(EXPERIENCE, COMBAT, MULTIPLIER1, StringUtils.getEntityConfigName(entity));
  273. }
  274. /* Materials */
  275. /**
  276. * Gets the raw XP given for breaking this block, this does not include modifiers
  277. * @param skill The skill to give XP for
  278. * @param blockType the type of block
  279. * @return the raw amount of XP for this block before modifiers
  280. */
  281. //public int getXp(PrimarySkillType skill, BlockType blockType) {
  282. public int getXp(PrimarySkillType skill, Material blockType) {
  283. //TODO: This is going to need to be changed, this code here is only placeholder
  284. String[] path = new String[]{ EXPERIENCE, StringUtils.getCapitalized(skill.toString()), blockType.toString()};
  285. return getIntValue(path);
  286. }
  287. /**
  288. * Checks if a block gives XP
  289. * This is used to determine whether or not mcMMO should track a block that is placed by a user, among other things.
  290. * 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
  291. * @param skill The skill to check for
  292. * @param blockType the type of block
  293. * @return true if the block does give XP
  294. */
  295. public boolean doesBlockGiveSkillXP(PrimarySkillType skill, Material blockType) {
  296. //TODO: This used to support wildcard characters, seems a bit unnecessary to do so.
  297. //TODO: This is going to need to be changed, this code here is only placeholder
  298. String[] path = new String[] {EXPERIENCE, StringUtils.getCapitalized(skill.toString()), blockType.toString()};
  299. return hasNode(path);
  300. }
  301. /*
  302. * Experience Bar Stuff
  303. */
  304. public boolean isPartyExperienceBarsEnabled() {
  305. return getBooleanValue(EXPERIENCE + BARS, UPDATE, PARTY);
  306. }
  307. public boolean isPassiveGainsExperienceBarsEnabled() {
  308. return getBooleanValue(EXPERIENCE + BARS, UPDATE, PASSIVE);
  309. }
  310. public boolean getDoExperienceBarsAlwaysUpdateTitle() {
  311. return getBooleanValue(EXPERIENCE + BARS, THIS_MAY_CAUSE_LAG, ALWAYS + UPDATE + TITLES_WHEN_XPIS_GAINED, ENABLE) || getAddExtraDetails();
  312. }
  313. public boolean getAddExtraDetails() {
  314. return getBooleanValue(EXPERIENCE + BARS, THIS_MAY_CAUSE_LAG, ALWAYS + UPDATE + TITLES_WHEN_XPIS_GAINED, EXTRA_DETAILS);
  315. }
  316. public boolean isExperienceBarsEnabled() {
  317. return getBooleanValue(EXPERIENCE + BARS, ENABLE);
  318. }
  319. public boolean isExperienceBarEnabled(PrimarySkillType primarySkillType) {
  320. return getBooleanValue(EXPERIENCE + BARS, StringUtils.getCapitalized(primarySkillType.toString()), ENABLE);
  321. }
  322. public BarColor getExperienceBarColor(PrimarySkillType primarySkillType) {
  323. String colorValueFromConfig = getStringValue(EXPERIENCE + BARS, StringUtils.getCapitalized(primarySkillType.toString()), COLOR);
  324. for (BarColor barColor : BarColor.values()) {
  325. if (barColor.toString().equalsIgnoreCase(colorValueFromConfig))
  326. return barColor;
  327. }
  328. //In case the value is invalid
  329. return BarColor.WHITE;
  330. }
  331. public BarStyle getExperienceBarStyle(PrimarySkillType primarySkillType) {
  332. String colorValueFromConfig = getStringValue(EXPERIENCE + BARS, StringUtils.getCapitalized(primarySkillType.toString()), BAR_STYLE);
  333. for (BarStyle barStyle : BarStyle.values()) {
  334. if (barStyle.toString().equalsIgnoreCase(colorValueFromConfig))
  335. return barStyle;
  336. }
  337. //In case the value is invalid
  338. return BarStyle.SOLID;
  339. }
  340. /* Acrobatics */
  341. public int getDodgeXPModifier() {
  342. return getIntValue(EXPERIENCE, ACROBATICS, DODGE);
  343. }
  344. public int getRollXPModifier() {
  345. return getIntValue(EXPERIENCE, ACROBATICS, ROLL);
  346. }
  347. public int getFallXPModifier() {
  348. return getIntValue(EXPERIENCE, ACROBATICS, FALL);
  349. }
  350. public double getFeatherFallXPModifier() {
  351. return getDoubleValue(EXPERIENCE, ACROBATICS, FEATHER_FALL_MULTIPLIER);
  352. }
  353. /* Alchemy */
  354. public double getPotionXP(PotionStage stage) {
  355. return getDoubleValue(EXPERIENCE, ALCHEMY, POTION_STAGE + stage.toNumerical());
  356. }
  357. /* Archery */
  358. public double getArcheryDistanceMultiplier() {
  359. return getDoubleValue(EXPERIENCE, ARCHERY, DISTANCE + MULTIPLIER1);
  360. }
  361. public int getFishingShakeXP() {
  362. return getIntValue(EXPERIENCE, FISHING, SHAKE);
  363. }
  364. /* Repair */
  365. public double getRepairXPBase() {
  366. return getDoubleValue(EXPERIENCE, REPAIR, BASE1);
  367. }
  368. public double getRepairXP(MaterialType repairMaterialType) {
  369. return getDoubleValue(EXPERIENCE, REPAIR, StringUtils.getCapitalized(repairMaterialType.toString()));
  370. }
  371. /* Taming */
  372. public int getTamingXP(EntityType type) {
  373. return getIntValue(EXPERIENCE, TAMING, ANIMAL_TAMING, StringUtils.getEntityConfigName(type));
  374. }
  375. }