ExperienceConfig.java 17 KB

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