mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-03 13:05:30 +02:00
Rewrote how SkillRanks were pulled for the new config system
This commit is contained in:
@@ -55,6 +55,7 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;
|
||||
import org.bukkit.Material;
|
||||
@@ -494,6 +495,14 @@ public final class ConfigManager {
|
||||
return configRanks.getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to programmatically grab rank data for skills
|
||||
* @return root node for the ranks config file
|
||||
*/
|
||||
public CommentedConfigurationNode getConfigRanksRootNode() {
|
||||
return configRanks.getRootNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this plugin is using retro mode
|
||||
* Retro mode is a 0-1000 skill system
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package com.gmail.nossr50.config;
|
||||
|
||||
import com.gmail.nossr50.config.hocon.skills.ranks.SkillRankProperty;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -10,8 +12,7 @@ import java.util.List;
|
||||
|
||||
@ConfigSerializable
|
||||
public class RankConfig extends ConfigValidated {
|
||||
public static final String RETRO_MODE = "RetroMode";
|
||||
public static final String STANDARD = "Standard";
|
||||
|
||||
//private static RankConfig instance;
|
||||
|
||||
public RankConfig() {
|
||||
@@ -55,43 +56,7 @@ public class RankConfig extends ConfigValidated {
|
||||
return reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
return findRankByRootAddress(rank, subSkillType.getRankConfigAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlock level for a subskill depending on the gamemode
|
||||
*
|
||||
* @param abstractSubSkill target subskill
|
||||
* @param rank the rank we are checking
|
||||
* @return the level requirement for a subskill at this particular rank
|
||||
*/
|
||||
public int getSubSkillUnlockLevel(AbstractSubSkill abstractSubSkill, int rank) {
|
||||
return findRankByRootAddress(rank, abstractSubSkill.getSubSkillType().getRankConfigAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlock level for a subskill depending on the gamemode
|
||||
*
|
||||
* @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) {
|
||||
String scalingKey = mcMMO.isRetroModeEnabled() ? RETRO_MODE : STANDARD;
|
||||
|
||||
String targetRank = "Rank_" + rank;
|
||||
|
||||
//key[0] = parent skill config node, key[1] subskill child node, scalingkey = retro/standard, targetrank = rank node
|
||||
return getIntValue(key[0], key[1], scalingKey, targetRank);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for valid keys for subskill ranks
|
||||
|
@@ -32,6 +32,10 @@ public class ConfigSectionSkillLevelCap {
|
||||
return useLevelCap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level cap for a skill, will return Integer.MAX_VALUE for values equal to or below 0
|
||||
* @return a levels max value
|
||||
*/
|
||||
public int getLevelCap() {
|
||||
if(levelCap <= 0)
|
||||
return Integer.MAX_VALUE;
|
||||
|
@@ -51,5 +51,4 @@ public class ConfigRanks {
|
||||
@Setting(value = "Repair", comment = "Configure when sub-skills unlock for Repair here.")
|
||||
private ConfigRanksRepair repair = new ConfigRanksRepair();
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.config.hocon.skills.ranks;
|
||||
|
||||
import com.gmail.nossr50.api.exceptions.MissingSkillPropertyDefinition;
|
||||
import com.gmail.nossr50.datatypes.skills.properties.SkillProperty;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -44,6 +45,26 @@ public class SkillRankProperty implements SkillProperty {
|
||||
retroRanks = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unlock level for this skill as defined by this SkillRankProperty
|
||||
* @param retroMode whether or not mcMMO is using RetroMode, true for if it is
|
||||
* @param targetRank the rank to get the unlock level for
|
||||
* @return the unlock level for target rank
|
||||
*/
|
||||
public int getUnlockLevel(boolean retroMode, int targetRank) throws MissingSkillPropertyDefinition {
|
||||
if(retroMode) {
|
||||
if(retroRanks.get(targetRank) == null) {
|
||||
throw new MissingSkillPropertyDefinition("No definition found for rank:"+targetRank+" using Retro scaling");
|
||||
}
|
||||
return retroRanks.get(targetRank);
|
||||
} else {
|
||||
if(standardRanks.get(targetRank) == null) {
|
||||
throw new MissingSkillPropertyDefinition("No definition found for rank:"+targetRank+" using Standard scaling");
|
||||
}
|
||||
return standardRanks.get(targetRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setStandardRanks(HashMap<Integer, Integer> standardRanks) {
|
||||
this.standardRanks = standardRanks;
|
||||
}
|
||||
|
Reference in New Issue
Block a user