mcMMO/src/main/java/com/gmail/nossr50/config/RankConfig.java

138 lines
4.4 KiB
Java
Raw Normal View History

package com.gmail.nossr50.config;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
2019-02-16 16:09:48 -08:00
import com.gmail.nossr50.mcMMO;
import java.util.ArrayList;
import java.util.List;
2019-02-16 16:09:48 -08:00
public class RankConfig extends ConfigValidated {
//private static RankConfig instance;
2019-02-16 16:09:48 -08:00
public RankConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(),"skillranks.yml", true, true);
//this.instance = this;
}
2019-02-17 11:32:53 -08:00
/**
* This grabs an instance of this config class from the Config Manager
* This method is deprecated and will be removed in the future
* @see mcMMO#getConfigManager()
* @return the instance of this config
* @deprecated Please use mcMMO.getConfigManager() to grab a specific config instead
*/
@Deprecated
public static RankConfig getInstance() {
return mcMMO.getConfigManager().getRankConfig();
}
/*public static RankConfig getInstance() {
2019-02-16 16:09:48 -08:00
if (instance == null)
return new RankConfig();
2019-02-16 16:09:48 -08:00
return instance;
}*/
2019-02-16 16:09:48 -08:00
@Override
public void unload() {
2019-02-17 11:32:53 -08:00
//Do nothing
2019-02-16 16:09:48 -08:00
}
2019-02-16 16:09:48 -08:00
/**
* The version of this config
*
* @return
*/
@Override
public double getConfigVersion() {
return 1;
}
@Override
2019-02-16 16:09:48 -08:00
public List<String> validateKeys() {
List<String> reason = new ArrayList<String>();
/*
* In the future this method will check keys for all skills, but for now it only checks overhauled skills
*/
checkKeys(reason);
2019-02-16 16:09:48 -08:00
return reason;
}
/**
* Returns the unlock level for a subskill depending on the gamemode
2019-02-16 16:09:48 -08:00
*
* @param subSkillType target subskill
2019-02-16 16:09:48 -08:00
* @param rank the rank we are checking
* @return the level requirement for a subskill at this particular rank
*/
2019-02-16 16:09:48 -08:00
public int getSubSkillUnlockLevel(SubSkillType subSkillType, int rank) {
String key = subSkillType.getRankConfigAddress();
return findRankByRootAddress(rank, key);
}
/**
* Returns the unlock level for a subskill depending on the gamemode
2019-02-16 16:09:48 -08:00
*
* @param abstractSubSkill target subskill
2019-02-16 16:09:48 -08:00
* @param rank the rank we are checking
* @return the level requirement for a subskill at this particular rank
*/
2019-02-16 16:09:48 -08:00
public int getSubSkillUnlockLevel(AbstractSubSkill abstractSubSkill, int rank) {
String key = abstractSubSkill.getPrimaryKeyName() + "." + abstractSubSkill.getConfigKeyName();
return findRankByRootAddress(rank, key);
}
/**
* Returns the unlock level for a subskill depending on the gamemode
2019-02-16 16:09:48 -08:00
*
* @param key root address of the subskill in the rankskills.yml file
* @param rank the rank we are checking
* @return the level requirement for a subskill at this particular rank
*/
private int findRankByRootAddress(int rank, String key) {
2019-02-17 11:32:53 -08:00
String scalingKey = MainConfig.getInstance().getIsRetroMode() ? ".RetroMode." : ".Standard.";
String targetRank = "Rank_" + rank;
key += scalingKey;
key += targetRank;
2019-02-16 16:09:48 -08:00
return getIntValue(key);
}
/**
* Checks for valid keys for subskill ranks
*/
2019-02-16 16:09:48 -08:00
private void checkKeys(List<String> reasons) {
//For now we will only check ranks of stuff I've overhauled
2019-02-16 16:09:48 -08:00
for (SubSkillType subSkillType : SubSkillType.values()) {
//Keeping track of the rank requirements and making sure there are no logical errors
int curRank = 0;
int prevRank = 0;
2019-02-16 16:09:48 -08:00
for (int x = 0; x < subSkillType.getNumRanks(); x++) {
if (curRank > 0)
prevRank = curRank;
curRank = getSubSkillUnlockLevel(subSkillType, x);
//Do we really care if its below 0? Probably not
2019-02-16 16:09:48 -08:00
if (curRank < 0) {
reasons.add(subSkillType.getAdvConfigAddress() + ".Rank_Levels.Rank_" + curRank + ".LevelReq should be above or equal to 0!");
}
2019-02-16 16:09:48 -08:00
if (prevRank > curRank) {
//We're going to allow this but we're going to warn them
2019-02-17 11:32:53 -08:00
mcMMO.p.getLogger().info("You have the ranks for the subskill " + subSkillType.toString() + " set up poorly, sequential ranks should have ascending requirements");
}
}
}
}
}