Fix skill property registration method

This commit is contained in:
nossr50 2019-06-13 16:48:49 -07:00
parent 9e336c8a6f
commit b4e612b15b
4 changed files with 71 additions and 23 deletions

View File

@ -1,8 +1,16 @@
package com.gmail.nossr50.config.hocon.skills.woodcutting; package com.gmail.nossr50.config.hocon.skills.woodcutting;
import com.gmail.nossr50.config.ConfigConstants;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ConfigSerializable @ConfigSerializable
public class ConfigWoodcutting { public class ConfigWoodcutting {
@Setting(value = ConfigConstants.SUB_SKILL_NODE, comment = "Settings for Woodcutting sub-skills")
private ConfigWoodcuttingSubskills subskills = new ConfigWoodcuttingSubskills();
public ConfigWoodcuttingSubskills getSubskills() {
return subskills;
}
} }

View File

@ -0,0 +1,28 @@
package com.gmail.nossr50.config.hocon.skills.woodcutting;
import com.gmail.nossr50.config.ConfigConstants;
import com.gmail.nossr50.datatypes.skills.properties.AbstractMaxBonusLevel;
import com.gmail.nossr50.datatypes.skills.properties.MaxBonusLevel;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ConfigSerializable
public class ConfigWoodcuttingHarvest {
private static final double MAX_CHANCE_DEFAULT = 100.0;
@Setting(value = ConfigConstants.MAX_CHANCE_FIELD_NAME, comment = ConfigConstants.MAX_CHANCE_FIELD_DESCRIPTION)
private double maxChance = MAX_CHANCE_DEFAULT;
@Setting(value = ConfigConstants.MAX_BONUS_LEVEL_FIELD_NAME)
private MaxBonusLevel maxBonusLevel = new AbstractMaxBonusLevel(100);
public double getMaxChance() {
return maxChance;
}
public MaxBonusLevel getMaxBonusLevel() {
return maxBonusLevel;
}
}

View File

@ -0,0 +1,15 @@
package com.gmail.nossr50.config.hocon.skills.woodcutting;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ConfigSerializable
public class ConfigWoodcuttingSubskills {
@Setting(value = "Harvest-Lumber")
private ConfigWoodcuttingHarvest harvest = new ConfigWoodcuttingHarvest();
public ConfigWoodcuttingHarvest getHarvest() {
return harvest;
}
}

View File

@ -7,6 +7,7 @@ import com.gmail.nossr50.datatypes.skills.properties.MaxBonusLevel;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.random.InvalidStaticChance; import com.gmail.nossr50.util.random.InvalidStaticChance;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ValueType;
import ninja.leaping.configurate.commented.CommentedConfigurationNode; import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException; import ninja.leaping.configurate.objectmapping.ObjectMappingException;
@ -78,30 +79,26 @@ public class SkillPropertiesManager {
//Check if the Sub-Skill node has a child matching this subskill name //Check if the Sub-Skill node has a child matching this subskill name
if (subSkillNode != null) { if (subSkillNode != null) {
//Check for all the various mcMMO skill properties //Register Max Bonus if it exists
for(Iterator<? extends CommentedConfigurationNode> it = subSkillNode.getChildrenList().iterator(); it.hasNext();) { if(getNodeIfReal(subSkillNode, ConfigConstants.MAX_BONUS_LEVEL_FIELD_NAME) != null) {
attemptRegisterMaxBonusLevel(subSkillType, subSkillNode.getNode(ConfigConstants.MAX_BONUS_LEVEL_FIELD_NAME));
CommentedConfigurationNode childNode = it.next();
Object lastObjectInPath = childNode.getPath()[childNode.getPath().length - 1];
String nodeName = lastObjectInPath.toString();
switch(nodeName) {
case ConfigConstants.MAX_BONUS_LEVEL_FIELD_NAME:
attemptRegisterMaxBonusLevel(subSkillType, childNode);
break;
case ConfigConstants.MAX_CHANCE_FIELD_NAME:
attemptRegisterMaxChance(subSkillType, childNode);
break;
case ConfigConstants.STATIC_ACTIVATION_FIELD_NAME:
attemptRegisterStaticChance(subSkillType, childNode);
break;
case ConfigConstants.MAX_BONUS_PERCENTAGE_FIELD_NAME:
attemptRegisterMaxBonusPercentage(subSkillType, childNode);
break;
} }
//Register Max Chance if it exists
if(getNodeIfReal(subSkillNode, ConfigConstants.MAX_CHANCE_FIELD_NAME) != null) {
attemptRegisterMaxChance(subSkillType, getNodeIfReal(subSkillNode, ConfigConstants.MAX_CHANCE_FIELD_NAME));
} }
//Register Static Activation Chance if it exists
if(getNodeIfReal(subSkillNode, ConfigConstants.STATIC_ACTIVATION_FIELD_NAME) != null) {
attemptRegisterStaticChance(subSkillType, getNodeIfReal(subSkillNode, ConfigConstants.STATIC_ACTIVATION_FIELD_NAME));
}
//Register Max Bonus Percentage if it exists
if(getNodeIfReal(subSkillNode, ConfigConstants.MAX_BONUS_PERCENTAGE_FIELD_NAME) != null) {
attemptRegisterMaxBonusPercentage(subSkillType, getNodeIfReal(subSkillNode, ConfigConstants.MAX_BONUS_PERCENTAGE_FIELD_NAME));
}
} }
} }
} }