|
@@ -2,8 +2,10 @@ package com.gmail.nossr50.config;
|
|
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
|
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
|
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
public class RankConfig extends AutoUpdateConfigLoader {
|
|
public class RankConfig extends AutoUpdateConfigLoader {
|
|
@@ -54,6 +56,18 @@ public class RankConfig extends AutoUpdateConfigLoader {
|
|
return findRankByRootAddress(rank, key);
|
|
return findRankByRootAddress(rank, key);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns the unlock level for a subskill depending on the gamemode
|
|
|
|
+ * @param subSkillType target subskill
|
|
|
|
+ * @param rank the rank we are checking
|
|
|
|
+ * @return the level requirement for a subskill at this particular rank
|
|
|
|
+ */
|
|
|
|
+ public int getSubSkillUnlockLevel(SubSkillType subSkillType, int rank, boolean retroMode)
|
|
|
|
+ {
|
|
|
|
+ String key = getRankAddressKey(subSkillType, rank, retroMode);
|
|
|
|
+ return config.getInt(key, getInternalConfig().getInt(key));
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns the unlock level for a subskill depending on the gamemode
|
|
* Returns the unlock level for a subskill depending on the gamemode
|
|
* @param abstractSubSkill target subskill
|
|
* @param abstractSubSkill target subskill
|
|
@@ -84,12 +98,61 @@ public class RankConfig extends AutoUpdateConfigLoader {
|
|
return config.getInt(key);
|
|
return config.getInt(key);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public String getRankAddressKey(SubSkillType subSkillType, int rank, boolean retroMode) {
|
|
|
|
+ String key = subSkillType.getRankConfigAddress();
|
|
|
|
+ String scalingKey = retroMode ? ".RetroMode." : ".Standard.";
|
|
|
|
+
|
|
|
|
+ String targetRank = "Rank_" + rank;
|
|
|
|
+
|
|
|
|
+ key += scalingKey;
|
|
|
|
+ key += targetRank;
|
|
|
|
+
|
|
|
|
+ return key;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String getRankAddressKey(AbstractSubSkill subSkillType, int rank, boolean retroMode) {
|
|
|
|
+ String key = subSkillType.getPrimaryKeyName() + "." + subSkillType.getConfigKeyName();
|
|
|
|
+ String scalingKey = retroMode ? ".RetroMode." : ".Standard.";
|
|
|
|
+
|
|
|
|
+ String targetRank = "Rank_" + rank;
|
|
|
|
+
|
|
|
|
+ key += scalingKey;
|
|
|
|
+ key += targetRank;
|
|
|
|
+
|
|
|
|
+ return key;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void resetRankValue(@NotNull SubSkillType subSkillType, int rank, boolean retroMode) {
|
|
|
|
+ String key = getRankAddressKey(subSkillType, rank, retroMode);
|
|
|
|
+ int defaultValue = getInternalConfig().getInt(key);
|
|
|
|
+ config.set(key, defaultValue);
|
|
|
|
+ plugin.getLogger().info(key +" set to a value of: " + defaultValue);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Checks for valid keys for subskill ranks
|
|
* Checks for valid keys for subskill ranks
|
|
*/
|
|
*/
|
|
- private void checkKeys(List<String> reasons)
|
|
|
|
|
|
+ private void checkKeys(@NotNull List<String> reasons)
|
|
{
|
|
{
|
|
|
|
+ HashSet<SubSkillType> badSkillSetup = new HashSet<>();
|
|
|
|
+
|
|
//For now we will only check ranks of stuff I've overhauled
|
|
//For now we will only check ranks of stuff I've overhauled
|
|
|
|
+ checkConfig(reasons, badSkillSetup, true);
|
|
|
|
+ checkConfig(reasons, badSkillSetup, false);
|
|
|
|
+
|
|
|
|
+ //Fix bad entries
|
|
|
|
+ if(badSkillSetup.isEmpty())
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ plugin.getLogger().info("(FIXING CONFIG) mcMMO is correcting a few mistakes found in your skill rank config setup");
|
|
|
|
+
|
|
|
|
+ for(SubSkillType subSkillType : badSkillSetup) {
|
|
|
|
+ plugin.getLogger().info("(FIXING CONFIG) Resetting rank config settings for skill named - "+subSkillType.toString());
|
|
|
|
+ fixBadEntries(subSkillType);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void checkConfig(@NotNull List<String> reasons, @NotNull HashSet<SubSkillType> badSkillSetup, boolean retroMode) {
|
|
for(SubSkillType subSkillType : SubSkillType.values())
|
|
for(SubSkillType subSkillType : SubSkillType.values())
|
|
{
|
|
{
|
|
//Keeping track of the rank requirements and making sure there are no logical errors
|
|
//Keeping track of the rank requirements and making sure there are no logical errors
|
|
@@ -98,23 +161,42 @@ public class RankConfig extends AutoUpdateConfigLoader {
|
|
|
|
|
|
for(int x = 0; x < subSkillType.getNumRanks(); x++)
|
|
for(int x = 0; x < subSkillType.getNumRanks(); x++)
|
|
{
|
|
{
|
|
|
|
+ int index = x+1;
|
|
|
|
+
|
|
if(curRank > 0)
|
|
if(curRank > 0)
|
|
prevRank = curRank;
|
|
prevRank = curRank;
|
|
|
|
|
|
- curRank = getSubSkillUnlockLevel(subSkillType, x);
|
|
|
|
|
|
+ curRank = getSubSkillUnlockLevel(subSkillType, index, retroMode);
|
|
|
|
|
|
//Do we really care if its below 0? Probably not
|
|
//Do we really care if its below 0? Probably not
|
|
if(curRank < 0)
|
|
if(curRank < 0)
|
|
{
|
|
{
|
|
- reasons.add(subSkillType.getAdvConfigAddress() + ".Rank_Levels.Rank_"+curRank+".LevelReq should be above or equal to 0!");
|
|
|
|
|
|
+ reasons.add("(CONFIG ISSUE) " + subSkillType.toString() + " should not have any ranks that require a negative level!");
|
|
|
|
+ badSkillSetup.add(subSkillType);
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
|
|
if(prevRank > curRank)
|
|
if(prevRank > curRank)
|
|
{
|
|
{
|
|
//We're going to allow this but we're going to warn them
|
|
//We're going to allow this but we're going to warn them
|
|
- plugin.getLogger().info("You have the ranks for the subskill "+ subSkillType.toString()+" set up poorly, sequential ranks should have ascending requirements");
|
|
|
|
|
|
+ plugin.getLogger().info("(CONFIG ISSUE) You have the ranks for the subskill "+ subSkillType.toString()+" set up poorly, sequential ranks should have ascending requirements");
|
|
|
|
+ badSkillSetup.add(subSkillType);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void fixBadEntries(@NotNull SubSkillType subSkillType) {
|
|
|
|
+ for(int x = 0; x < subSkillType.getNumRanks(); x++)
|
|
|
|
+ {
|
|
|
|
+ int index = x+1;
|
|
|
|
+
|
|
|
|
+ //Reset Retromode entries
|
|
|
|
+ resetRankValue(subSkillType, index, true);
|
|
|
|
+ //Reset Standard Entries
|
|
|
|
+ resetRankValue(subSkillType, index, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ saveConfig();
|
|
|
|
+ }
|
|
}
|
|
}
|