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.ArrayList;
import java.util.List; import java.util.List;
import com.gmail.nossr50.mcMMO;
public class AdvancedConfig extends AutoUpdateConfigLoader { public class AdvancedConfig extends AutoUpdateConfigLoader {
private static AdvancedConfig instance; private static AdvancedConfig instance;
private AdvancedConfig() { private AdvancedConfig() {
super("advanced.yml"); super("advanced.yml");
loadKeys(); validate();
} }
public static AdvancedConfig getInstance() { public static AdvancedConfig getInstance() {
@ -22,7 +20,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
} }
@Override @Override
protected void loadKeys() { protected boolean validateKeys() {
// Validate all the settings! // Validate all the settings!
List<String> reason = new ArrayList<String>(); 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!"); reason.add("Kraken.Attack_Damage should be at least 1!");
} }
// Check if there were any errors return noErrorsInConfig(reason);
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;
}
} }
@Override
protected void loadKeys() {}
/* GENERAL */ /* GENERAL */
public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); } public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); }
public int getEnchantBuff() { return config.getInt("Skills.General.Ability_EnchantBuff", 5); } 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.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.MobHealthbarType; import com.gmail.nossr50.datatypes.MobHealthbarType;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
@ -20,7 +19,7 @@ public class Config extends AutoUpdateConfigLoader {
private Config() { private Config() {
super("config.yml"); super("config.yml");
loadKeys(); validate();
} }
public static Config getInstance() { public static Config getInstance() {
@ -32,7 +31,7 @@ public class Config extends AutoUpdateConfigLoader {
} }
@Override @Override
protected void loadKeys() { protected boolean validateKeys() {
// Validate all the settings! // Validate all the settings!
List<String> reason = new ArrayList<String>(); 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!"); reason.add("Experience.Formula.Curve_Modifier should be at least 0!");
} }
// Check if there were any errors return noErrorsInConfig(reason);
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;
}
} }
@Override
protected void loadKeys() {}
/* /*
* GENERAL SETTINGS * GENERAL SETTINGS
*/ */

View File

@ -92,6 +92,10 @@ public abstract class ConfigLoader {
} }
} }
protected boolean validateKeys() {
return true;
}
protected boolean noErrorsInConfig(List<String> issues) { protected boolean noErrorsInConfig(List<String> issues) {
for (String issue : issues) { for (String issue : issues) {
plugin.getLogger().warning(issue); plugin.getLogger().warning(issue);
@ -99,4 +103,15 @@ public abstract class ConfigLoader {
return issues.isEmpty(); 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.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -83,9 +82,7 @@ public class TreasureConfig extends ConfigLoader {
return; return;
} }
Set<String> treasureConfigSet = treasureSection.getKeys(false); for (String treasureName : treasureSection.getKeys(false)) {
for (String treasureName : treasureConfigSet) {
// Validate all the things! // Validate all the things!
List<String> reason = new ArrayList<String>(); List<String> reason = new ArrayList<String>();

View File

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