Validate in a seperate function.

This commit is contained in:
GJ 2013-08-20 15:51:12 -04:00
parent 045d74fb9d
commit 07dd460d78
5 changed files with 29 additions and 32 deletions

View File

@ -3,14 +3,12 @@ package com.gmail.nossr50.config;
import java.util.ArrayList;
import java.util.List;
import com.gmail.nossr50.mcMMO;
public class AdvancedConfig extends AutoUpdateConfigLoader {
private static AdvancedConfig instance;
private AdvancedConfig() {
super("advanced.yml");
loadKeys();
validate();
}
public static AdvancedConfig getInstance() {
@ -22,7 +20,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
}
@Override
protected void loadKeys() {
protected boolean validateKeys() {
// Validate all the settings!
List<String> reason = new ArrayList<String>();
@ -778,17 +776,12 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
reason.add("Kraken.Attack_Damage should be at least 1!");
}
// Check if there were any errors
if (noErrorsInConfig(reason)) {
mcMMO.p.debug("No errors found in " + fileName + "!");
}
else {
mcMMO.p.getLogger().warning("Errors were found in " + fileName + "! mcMMO was disabled!");
mcMMO.p.getServer().getPluginManager().disablePlugin(mcMMO.p);
mcMMO.p.noErrorsInConfigFiles = false;
}
return noErrorsInConfig(reason);
}
@Override
protected void loadKeys() {}
/* GENERAL */
public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); }
public int getEnchantBuff() { return config.getInt("Skills.General.Ability_EnchantBuff", 5); }

View File

@ -8,7 +8,6 @@ import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.MobHealthbarType;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
@ -20,7 +19,7 @@ public class Config extends AutoUpdateConfigLoader {
private Config() {
super("config.yml");
loadKeys();
validate();
}
public static Config getInstance() {
@ -32,7 +31,7 @@ public class Config extends AutoUpdateConfigLoader {
}
@Override
protected void loadKeys() {
protected boolean validateKeys() {
// Validate all the settings!
List<String> reason = new ArrayList<String>();
@ -197,17 +196,12 @@ public class Config extends AutoUpdateConfigLoader {
reason.add("Experience.Formula.Curve_Modifier should be at least 0!");
}
// Check if there were any errors
if (noErrorsInConfig(reason)) {
mcMMO.p.debug("No errors found in " + fileName + "!");
}
else {
mcMMO.p.getLogger().warning("Errors were found in " + fileName + "! mcMMO was disabled!");
mcMMO.p.getServer().getPluginManager().disablePlugin(mcMMO.p);
mcMMO.p.noErrorsInConfigFiles = false;
}
return noErrorsInConfig(reason);
}
@Override
protected void loadKeys() {}
/*
* GENERAL SETTINGS
*/

View File

@ -92,6 +92,10 @@ public abstract class ConfigLoader {
}
}
protected boolean validateKeys() {
return true;
}
protected boolean noErrorsInConfig(List<String> issues) {
for (String issue : issues) {
plugin.getLogger().warning(issue);
@ -99,4 +103,15 @@ public abstract class ConfigLoader {
return issues.isEmpty();
}
protected void validate() {
if (validateKeys()) {
plugin.debug("No errors found in " + fileName + "!");
}
else {
plugin.getLogger().warning("Errors were found in " + fileName + "! mcMMO was disabled!");
plugin.getServer().getPluginManager().disablePlugin(plugin);
plugin.noErrorsInConfigFiles = false;
}
}
}

View File

@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
@ -83,9 +82,7 @@ public class TreasureConfig extends ConfigLoader {
return;
}
Set<String> treasureConfigSet = treasureSection.getKeys(false);
for (String treasureName : treasureConfigSet) {
for (String treasureName : treasureSection.getKeys(false)) {
// Validate all the things!
List<String> reason = new ArrayList<String>();

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.skills.child;
import java.util.EnumSet;
import java.util.List;
import org.bukkit.configuration.file.YamlConfiguration;
@ -22,11 +21,10 @@ public class ChildConfig extends AutoUpdateConfigLoader {
for (SkillType skill : SkillType.childSkills()) {
plugin.debug("Finding parents of " + skill.name());
List<String> parentNames = config.getStringList(StringUtils.getCapitalized(skill.name()));
EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class);
boolean useDefaults = false; // If we had an error we back out and use defaults
for (String name : parentNames) {
for (String name : config.getStringList(StringUtils.getCapitalized(skill.name()))) {
try {
SkillType parentSkill = SkillType.valueOf(name.toUpperCase());
FamilyTree.enforceNotChildSkill(parentSkill);