ExperienceConfig.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. package com.gmail.nossr50.config.experience;
  2. import static com.gmail.nossr50.util.text.ConfigStringUtils.getConfigEntityTypeString;
  3. import static com.gmail.nossr50.util.text.ConfigStringUtils.getMaterialConfigString;
  4. import com.gmail.nossr50.config.BukkitConfig;
  5. import com.gmail.nossr50.datatypes.experience.FormulaType;
  6. import com.gmail.nossr50.datatypes.skills.MaterialType;
  7. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  8. import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage;
  9. import com.gmail.nossr50.util.text.StringUtils;
  10. import java.util.ArrayList;
  11. import java.util.HashMap;
  12. import java.util.List;
  13. import java.util.Map;
  14. import org.bukkit.Material;
  15. import org.bukkit.block.Block;
  16. import org.bukkit.block.BlockState;
  17. import org.bukkit.block.data.BlockData;
  18. import org.bukkit.boss.BarColor;
  19. import org.bukkit.boss.BarStyle;
  20. import org.bukkit.entity.EntityType;
  21. public class ExperienceConfig extends BukkitConfig {
  22. private static ExperienceConfig instance;
  23. final private Map<PrimarySkillType, Map<Material, Integer>> blockExperienceMap = new HashMap<>();
  24. private ExperienceConfig() {
  25. super("experience.yml");
  26. validate();
  27. }
  28. public static ExperienceConfig getInstance() {
  29. if (instance == null) {
  30. instance = new ExperienceConfig();
  31. for (PrimarySkillType skill : PrimarySkillType.values()) {
  32. final Map<Material, Integer> experienceMap = new HashMap<>();
  33. instance.blockExperienceMap.put(skill, experienceMap);
  34. for (Material material : Material.values()) {
  35. int xp = instance.getConfigXp(skill, material);
  36. if (xp > 0) {
  37. experienceMap.put(material, xp);
  38. }
  39. }
  40. }
  41. }
  42. return instance;
  43. }
  44. @Override
  45. protected void loadKeys() {
  46. }
  47. @Override
  48. protected boolean validateKeys() {
  49. List<String> reason = new ArrayList<>();
  50. /*
  51. * FORMULA SETTINGS
  52. */
  53. /* Curve values */
  54. if (getMultiplier(FormulaType.EXPONENTIAL) <= 0) {
  55. reason.add(
  56. "Experience_Formula.Exponential_Values.multiplier should be greater than 0!");
  57. }
  58. if (getMultiplier(FormulaType.LINEAR) <= 0) {
  59. reason.add("Experience_Formula.Linear_Values.multiplier should be greater than 0!");
  60. }
  61. if (getExponent(FormulaType.EXPONENTIAL) <= 0) {
  62. reason.add("Experience_Formula.Exponential_Values.exponent should be greater than 0!");
  63. }
  64. /* Global modifier */
  65. if (getExperienceGainsGlobalMultiplier() <= 0) {
  66. reason.add("Experience_Formula.Multiplier.Global should be greater than 0!");
  67. }
  68. /* PVP modifier */
  69. if (getPlayerVersusPlayerXP() < 0) {
  70. reason.add("Experience_Formula.Multiplier.PVP should be at least 0!");
  71. }
  72. /* Spawned Mob modifier */
  73. if (getSpawnedMobXpMultiplier() < 0) {
  74. reason.add("Experience_Formula.Mobspawners.Multiplier should be at least 0!");
  75. }
  76. /* Bred Mob modifier */
  77. if (getBredMobXpMultiplier() < 0) {
  78. reason.add("Experience_Formula.Breeding.Multiplier should be at least 0!");
  79. }
  80. /* Conversion */
  81. if (getExpModifier() <= 0) {
  82. reason.add("Conversion.Exp_Modifier should be greater than 0!");
  83. }
  84. /*
  85. * XP SETTINGS
  86. */
  87. /* Alchemy */
  88. for (PotionStage potionStage : PotionStage.values()) {
  89. if (getPotionXP(potionStage) < 0) {
  90. reason.add(
  91. "Experience_Values.Alchemy.Potion_Stage_" + potionStage.toNumerical()
  92. + " should be at least 0!");
  93. }
  94. }
  95. /* Archery */
  96. if (getArcheryDistanceMultiplier() < 0) {
  97. reason.add("Experience_Values.Archery.Distance_Multiplier should be at least 0!");
  98. }
  99. /* Combat XP Multipliers */
  100. if (getAnimalsXP() < 0) {
  101. reason.add("Experience_Values.Combat.Multiplier.Animals should be at least 0!");
  102. }
  103. if (getDodgeXPModifier() < 0) {
  104. reason.add("Skills.Acrobatics.Dodge_XP_Modifier should be at least 0!");
  105. }
  106. if (getRollXPModifier() < 0) {
  107. reason.add("Skills.Acrobatics.Roll_XP_Modifier should be at least 0!");
  108. }
  109. if (getFallXPModifier() < 0) {
  110. reason.add("Skills.Acrobatics.Fall_XP_Modifier should be at least 0!");
  111. }
  112. /* Fishing */
  113. // TODO: Add validation for each fish type once enum is available.
  114. if (getFishingShakeXP() <= 0) {
  115. reason.add("Experience_Values.Fishing.Shake should be greater than 0!");
  116. }
  117. /* Repair */
  118. if (getRepairXPBase() <= 0) {
  119. reason.add("Experience_Values.Repair.Base should be greater than 0!");
  120. }
  121. /* Taming */
  122. if (getTamingXP(EntityType.WOLF) <= 0) {
  123. reason.add("Experience_Values.Taming.Animal_Taming.Wolf should be greater than 0!");
  124. }
  125. if (getTamingXP(EntityType.OCELOT) <= 0) {
  126. reason.add("Experience_Values.Taming.Animal_Taming.Ocelot should be greater than 0!");
  127. }
  128. return noErrorsInConfig(reason);
  129. }
  130. public boolean isEarlyGameBoostEnabled() {
  131. return config.getBoolean("EarlyGameBoost.Enabled", true);
  132. }
  133. /*
  134. * FORMULA SETTINGS
  135. */
  136. /* EXPLOIT TOGGLES */
  137. public boolean isSnowExploitPrevented() {
  138. return config.getBoolean("ExploitFix.SnowGolemExcavation", true);
  139. }
  140. public boolean isEndermanEndermiteFarmingPrevented() {
  141. return config.getBoolean("ExploitFix.EndermanEndermiteFarms", true);
  142. }
  143. public boolean isPistonCheatingPrevented() {
  144. return config.getBoolean("ExploitFix.PistonCheating", true);
  145. }
  146. public boolean isPistonExploitPrevented() {
  147. return config.getBoolean("ExploitFix.Pistons", false);
  148. }
  149. public boolean allowUnsafeEnchantments() {
  150. return config.getBoolean("ExploitFix.UnsafeEnchantments", false);
  151. }
  152. public boolean isCOTWBreedingPrevented() {
  153. return config.getBoolean("ExploitFix.COTWBreeding", true);
  154. }
  155. public boolean isNPCInteractionPrevented() {
  156. return config.getBoolean("ExploitFix.PreventPluginNPCInteraction", true);
  157. }
  158. public boolean isArmorStandInteractionPrevented() {
  159. return config.getBoolean("ExploitFix.PreventArmorStandInteraction", true);
  160. }
  161. public boolean isFishingExploitingPrevented() {
  162. return config.getBoolean("ExploitFix.Fishing", true);
  163. }
  164. public int getFishingExploitingOptionMoveRange() {
  165. return config.getInt("Fishing_ExploitFix_Options.MoveRange", 3);
  166. }
  167. public int getFishingExploitingOptionOverFishLimit() {
  168. return config.getInt("Fishing_ExploitFix_Options.OverFishLimit", 10);
  169. }
  170. public boolean isAcrobaticsExploitingPrevented() {
  171. return config.getBoolean("ExploitFix.Acrobatics", true);
  172. }
  173. public boolean isTreeFellerXPReduced() {
  174. return config.getBoolean("ExploitFix.TreeFellerReducedXP", true);
  175. }
  176. /* Curve settings */
  177. public FormulaType getFormulaType() {
  178. return FormulaType.getFormulaType(config.getString("Experience_Formula.Curve", "LINEAR"));
  179. }
  180. public boolean getCumulativeCurveEnabled() {
  181. return config.getBoolean("Experience_Formula.Cumulative_Curve", false);
  182. }
  183. /* Curve values */
  184. public double getMultiplier(FormulaType type) {
  185. double def = type == FormulaType.LINEAR ? 20D : 0.1D;
  186. return config.getDouble(
  187. "Experience_Formula." + StringUtils.getCapitalized(type.toString())
  188. + "_Values.multiplier", def);
  189. }
  190. public int getBase(FormulaType type) {
  191. int def = type == FormulaType.LINEAR ? 1020 : 2000;
  192. return config.getInt("Experience_Formula." + StringUtils.getCapitalized(type.toString())
  193. + "_Values.base", def);
  194. }
  195. public double getExponent(FormulaType type) {
  196. return config.getDouble(
  197. "Experience_Formula." + StringUtils.getCapitalized(type.toString())
  198. + "_Values.exponent");
  199. }
  200. /* Global modifier */
  201. public double getExperienceGainsGlobalMultiplier() {
  202. return config.getDouble("Experience_Formula.Multiplier.Global", 1.0);
  203. }
  204. public void setExperienceGainsGlobalMultiplier(double value) {
  205. config.set("Experience_Formula.Multiplier.Global", value);
  206. }
  207. /* PVP modifier */
  208. public double getPlayerVersusPlayerXP() {
  209. return config.getDouble("Experience_Formula.Multiplier.PVP", 1.0);
  210. }
  211. /* Spawned Mob modifier */
  212. public double getSpawnedMobXpMultiplier() {
  213. return config.getDouble("Experience_Formula.Mobspawners.Multiplier", 0.0);
  214. }
  215. public double getEggXpMultiplier() {
  216. return config.getDouble("Experience_Formula.Eggs.Multiplier", 0.0);
  217. }
  218. public double getTamedMobXpMultiplier() {
  219. return config.getDouble("Experience_Formula.Player_Tamed.Multiplier", 0.0);
  220. }
  221. public double getNetherPortalXpMultiplier() {
  222. return config.getDouble("Experience_Formula.Nether_Portal.Multiplier", 0.0);
  223. }
  224. public double getBredMobXpMultiplier() {
  225. return config.getDouble("Experience_Formula.Breeding.Multiplier", 1.0);
  226. }
  227. /* Skill modifiers */
  228. public double getFormulaSkillModifier(PrimarySkillType skill) {
  229. return config.getDouble(
  230. "Experience_Formula.Skill_Multiplier." + StringUtils.getCapitalized(
  231. skill.toString()),
  232. 1D);
  233. }
  234. /* Custom XP perk */
  235. public double getCustomXpPerkBoost() {
  236. return config.getDouble("Experience_Formula.Custom_XP_Perk.Boost", 1.25);
  237. }
  238. /* Diminished Returns */
  239. public float getDiminishedReturnsCap() {
  240. return (float) config.getDouble("Dimished_Returns.Guaranteed_Minimum_Percentage", 0.05D);
  241. }
  242. public boolean getDiminishedReturnsEnabled() {
  243. return config.getBoolean("Diminished_Returns.Enabled", false);
  244. }
  245. public int getDiminishedReturnsThreshold(PrimarySkillType skill) {
  246. return config.getInt(
  247. "Diminished_Returns.Threshold." + StringUtils.getCapitalized(skill.toString()),
  248. 20000);
  249. }
  250. public int getDiminishedReturnsTimeInterval() {
  251. return config.getInt("Diminished_Returns.Time_Interval", 10);
  252. }
  253. /* Conversion */
  254. public double getExpModifier() {
  255. return config.getDouble("Conversion.Exp_Modifier", 1);
  256. }
  257. /*
  258. * XP SETTINGS
  259. */
  260. /* General Settings */
  261. public boolean getExperienceGainsPlayerVersusPlayerEnabled() {
  262. return config.getBoolean("Experience_Values.PVP.Rewards", true);
  263. }
  264. /* Combat XP Multipliers */
  265. public double getCombatXP(String entity) {
  266. return config.getDouble("Experience_Values.Combat.Multiplier." + entity);
  267. }
  268. public double getCombatXP(EntityType entity) {
  269. return config.getDouble(
  270. "Experience_Values.Combat.Multiplier." + getConfigEntityTypeString(entity).replace(
  271. " ", "_"));
  272. }
  273. public double getAnimalsXP(EntityType entity) {
  274. return config.getDouble(
  275. "Experience_Values.Combat.Multiplier." + getConfigEntityTypeString(entity).replace(
  276. " ", "_"),
  277. getAnimalsXP());
  278. }
  279. public double getAnimalsXP() {
  280. return config.getDouble("Experience_Values.Combat.Multiplier.Animals", 1.0);
  281. }
  282. public boolean hasCombatXP(EntityType entity) {
  283. return config.contains(
  284. "Experience_Values.Combat.Multiplier." + getConfigEntityTypeString(entity).replace(
  285. " ", "_"));
  286. }
  287. /* Materials */
  288. private int getConfigXp(PrimarySkillType skill, Material material) {
  289. // prevents exploit
  290. if (material == Material.LILY_PAD) {
  291. return 0;
  292. }
  293. final String baseString =
  294. "Experience_Values." + StringUtils.getCapitalized(skill.toString()) + ".";
  295. final String configPath = baseString + getMaterialConfigString(material);
  296. return config.getInt(configPath, 0);
  297. }
  298. public int getXp(PrimarySkillType skill, Material material) {
  299. return blockExperienceMap.get(skill).getOrDefault(material, 0);
  300. }
  301. public int getXp(PrimarySkillType skill, BlockState blockState) {
  302. return getXp(skill, blockState.getType());
  303. }
  304. public int getXp(PrimarySkillType skill, Block block) {
  305. Material material = block.getType();
  306. return getXp(skill, material);
  307. }
  308. public int getXp(PrimarySkillType skill, BlockData data) {
  309. return getXp(skill, data.getMaterial());
  310. }
  311. public boolean doesBlockGiveSkillXP(PrimarySkillType skill, Material material) {
  312. return getXp(skill, material) > 0;
  313. }
  314. @Deprecated(forRemoval = true, since = "2.2.024")
  315. public boolean doesBlockGiveSkillXP(PrimarySkillType skill, BlockData data) {
  316. return getXp(skill, data) > 0;
  317. }
  318. /*
  319. * Experience Bar Stuff
  320. */
  321. public boolean isPartyExperienceBarsEnabled() {
  322. return config.getBoolean("Experience_Bars.Update.Party", true);
  323. }
  324. public boolean isPassiveGainsExperienceBarsEnabled() {
  325. return config.getBoolean("Experience_Bars.Update.Passive", true);
  326. }
  327. public boolean getDoExperienceBarsAlwaysUpdateTitle() {
  328. return config.getBoolean(
  329. "Experience_Bars.ThisMayCauseLag.AlwaysUpdateTitlesWhenXPIsGained.Enable",
  330. false) || getAddExtraDetails();
  331. }
  332. public boolean getAddExtraDetails() {
  333. return config.getBoolean(
  334. "Experience_Bars.ThisMayCauseLag.AlwaysUpdateTitlesWhenXPIsGained.ExtraDetails",
  335. false);
  336. }
  337. public boolean useCombatHPCeiling() {
  338. return config.getBoolean("ExploitFix.Combat.XPCeiling.Enabled", true);
  339. }
  340. public int getCombatHPCeiling() {
  341. return config.getInt("ExploitFix.Combat.XPCeiling.HP_Modifier_Limit", 100);
  342. }
  343. public boolean isExperienceBarsEnabled() {
  344. return config.getBoolean("Experience_Bars.Enable", true);
  345. }
  346. public boolean isExperienceBarEnabled(PrimarySkillType primarySkillType) {
  347. return config.getBoolean(
  348. "Experience_Bars." + StringUtils.getCapitalized(primarySkillType.toString())
  349. + ".Enable", true);
  350. }
  351. public BarColor getExperienceBarColor(PrimarySkillType primarySkillType) {
  352. String colorValueFromConfig = config.getString(
  353. "Experience_Bars." + StringUtils.getCapitalized(primarySkillType.toString())
  354. + ".Color");
  355. for (BarColor barColor : BarColor.values()) {
  356. if (barColor.toString().equalsIgnoreCase(colorValueFromConfig)) {
  357. return barColor;
  358. }
  359. }
  360. //In case the value is invalid
  361. return BarColor.WHITE;
  362. }
  363. public BarStyle getExperienceBarStyle(PrimarySkillType primarySkillType) {
  364. String colorValueFromConfig = config.getString(
  365. "Experience_Bars." + StringUtils.getCapitalized(primarySkillType.toString())
  366. + ".BarStyle");
  367. for (BarStyle barStyle : BarStyle.values()) {
  368. if (barStyle.toString().equalsIgnoreCase(colorValueFromConfig)) {
  369. return barStyle;
  370. }
  371. }
  372. //In case the value is invalid
  373. return BarStyle.SOLID;
  374. }
  375. /* Acrobatics */
  376. public int getDodgeXPModifier() {
  377. return config.getInt("Experience_Values.Acrobatics.Dodge", 120);
  378. }
  379. public int getRollXPModifier() {
  380. return config.getInt("Experience_Values.Acrobatics.Roll", 80);
  381. }
  382. public int getFallXPModifier() {
  383. return config.getInt("Experience_Values.Acrobatics.Fall", 120);
  384. }
  385. public double getFeatherFallXPModifier() {
  386. return config.getDouble("Experience_Values.Acrobatics.FeatherFall_Multiplier", 2.0);
  387. }
  388. /* Alchemy */
  389. public double getPotionXP(PotionStage stage) {
  390. return config.getDouble(
  391. "Experience_Values.Alchemy.Potion_Brewing.Stage_" + stage.toNumerical(), 10D);
  392. }
  393. /* Archery */
  394. public double getArcheryDistanceMultiplier() {
  395. return config.getDouble("Experience_Values.Archery.Distance_Multiplier", 0.025);
  396. }
  397. public int getFishingShakeXP() {
  398. return config.getInt("Experience_Values.Fishing.Shake", 50);
  399. }
  400. /* Repair */
  401. public double getRepairXPBase() {
  402. return config.getDouble("Experience_Values.Repair.Base", 1000.0);
  403. }
  404. public double getRepairXP(MaterialType repairMaterialType) {
  405. return config.getDouble(
  406. "Experience_Values.Repair." + StringUtils.getCapitalized(
  407. repairMaterialType.toString()));
  408. }
  409. /* Taming */
  410. public int getTamingXP(EntityType type) {
  411. return config.getInt(
  412. "Experience_Values.Taming.Animal_Taming." + getConfigEntityTypeString(type));
  413. }
  414. public boolean preventStoneLavaFarming() {
  415. return config.getBoolean("ExploitFix.LavaStoneAndCobbleFarming", true);
  416. }
  417. public boolean limitXPOnTallPlants() {
  418. return config.getBoolean("ExploitFix.LimitTallPlantFarming", true);
  419. }
  420. }