RankConfig.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.gmail.nossr50.config;
  2. import com.gmail.nossr50.datatypes.skills.SubSkillType;
  3. import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
  4. import com.gmail.nossr50.mcMMO;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. public class RankConfig extends ConfigValidated {
  8. //private static RankConfig instance;
  9. public RankConfig() {
  10. //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true);
  11. super(mcMMO.p.getDataFolder().getAbsoluteFile(),"skillranks.yml", true);
  12. //this.instance = this;
  13. }
  14. /*public static RankConfig getInstance() {
  15. if (instance == null)
  16. return new RankConfig();
  17. return instance;
  18. }*/
  19. @Override
  20. public void unload() {
  21. instance = null;
  22. }
  23. /**
  24. * The version of this config
  25. *
  26. * @return
  27. */
  28. @Override
  29. public double getConfigVersion() {
  30. return 1;
  31. }
  32. @Override
  33. public List<String> validateKeys() {
  34. List<String> reason = new ArrayList<String>();
  35. /*
  36. * In the future this method will check keys for all skills, but for now it only checks overhauled skills
  37. */
  38. checkKeys(reason);
  39. return reason;
  40. }
  41. /**
  42. * Returns the unlock level for a subskill depending on the gamemode
  43. *
  44. * @param subSkillType target subskill
  45. * @param rank the rank we are checking
  46. * @return the level requirement for a subskill at this particular rank
  47. */
  48. public int getSubSkillUnlockLevel(SubSkillType subSkillType, int rank) {
  49. String key = subSkillType.getRankConfigAddress();
  50. return findRankByRootAddress(rank, key);
  51. }
  52. /**
  53. * Returns the unlock level for a subskill depending on the gamemode
  54. *
  55. * @param abstractSubSkill target subskill
  56. * @param rank the rank we are checking
  57. * @return the level requirement for a subskill at this particular rank
  58. */
  59. public int getSubSkillUnlockLevel(AbstractSubSkill abstractSubSkill, int rank) {
  60. String key = abstractSubSkill.getPrimaryKeyName() + "." + abstractSubSkill.getConfigKeyName();
  61. return findRankByRootAddress(rank, key);
  62. }
  63. /**
  64. * Returns the unlock level for a subskill depending on the gamemode
  65. *
  66. * @param key root address of the subskill in the rankskills.yml file
  67. * @param rank the rank we are checking
  68. * @return the level requirement for a subskill at this particular rank
  69. */
  70. private int findRankByRootAddress(int rank, String key) {
  71. String scalingKey = MainMainConfig.getInstance().getIsRetroMode() ? ".RetroMode." : ".Standard.";
  72. String targetRank = "Rank_" + rank;
  73. key += scalingKey;
  74. key += targetRank;
  75. return getIntValue(key);
  76. }
  77. /**
  78. * Checks for valid keys for subskill ranks
  79. */
  80. private void checkKeys(List<String> reasons) {
  81. //For now we will only check ranks of stuff I've overhauled
  82. for (SubSkillType subSkillType : SubSkillType.values()) {
  83. //Keeping track of the rank requirements and making sure there are no logical errors
  84. int curRank = 0;
  85. int prevRank = 0;
  86. for (int x = 0; x < subSkillType.getNumRanks(); x++) {
  87. if (curRank > 0)
  88. prevRank = curRank;
  89. curRank = getSubSkillUnlockLevel(subSkillType, x);
  90. //Do we really care if its below 0? Probably not
  91. if (curRank < 0) {
  92. reasons.add(subSkillType.getAdvConfigAddress() + ".Rank_Levels.Rank_" + curRank + ".LevelReq should be above or equal to 0!");
  93. }
  94. if (prevRank > curRank) {
  95. //We're going to allow this but we're going to warn them
  96. plugin.getLogger().info("You have the ranks for the subskill " + subSkillType.toString() + " set up poorly, sequential ranks should have ascending requirements");
  97. }
  98. }
  99. }
  100. }
  101. }