diff --git a/src/main/java/com/gmail/nossr50/config/ConfigValidated.java b/src/main/java/com/gmail/nossr50/config/ConfigValidated.java index 61e225ee7..76b8770c1 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigValidated.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigValidated.java @@ -1,15 +1,12 @@ package com.gmail.nossr50.config; -import com.gmail.nossr50.mcMMO; - import java.io.File; -import java.util.List; /** * This class is used for config files that validate their entries */ -public abstract class ConfigValidated extends Config implements DefaultKeys { +public abstract class ConfigValidated extends Config implements UnsafeValueValidation { /** * @param parentFolderPath Path to the "parent" folder on disk * @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files @@ -33,25 +30,4 @@ public abstract class ConfigValidated extends Config implements DefaultKeys { super(parentFolderFile, relativePath, mergeNewKeys, copyDefaults, removeOldKeys); validateEntries(); } - - /** - * Prints all errors found when validating the config - */ - private void validateEntries() - { - /* - * Print Errors about Keys - */ - - List validKeyErrors = validateKeys(); // Validate Keys - - if(validKeyErrors != null && validKeyErrors.size() > 0) - { - for(String error : validKeyErrors) - { - mcMMO.p.getLogger().severe(error); - } - } - } - } diff --git a/src/main/java/com/gmail/nossr50/config/DefaultKeys.java b/src/main/java/com/gmail/nossr50/config/DefaultKeys.java deleted file mode 100644 index 3d94ccd15..000000000 --- a/src/main/java/com/gmail/nossr50/config/DefaultKeys.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.gmail.nossr50.config; - -import java.util.List; - -/** - * This is for config validation - */ -public interface DefaultKeys { - List validateKeys(); -} diff --git a/src/main/java/com/gmail/nossr50/config/UnsafeValueValidation.java b/src/main/java/com/gmail/nossr50/config/UnsafeValueValidation.java new file mode 100644 index 000000000..a6f18a2d4 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/UnsafeValueValidation.java @@ -0,0 +1,32 @@ +package com.gmail.nossr50.config; + +import com.gmail.nossr50.mcMMO; + +import java.util.List; + +/** + * This is for config validation + */ +public interface UnsafeValueValidation { + List validateKeys(); + + /** + * Prints all errors found when validating the config + */ + default void validateEntries() + { + /* + * Print Errors about Keys + */ + + List validKeyErrors = validateKeys(); // Validate Keys + + if(validKeyErrors != null && validKeyErrors.size() > 0) + { + for(String error : validKeyErrors) + { + mcMMO.p.getLogger().severe(error); + } + } + } +} diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java index f44e0cc75..4718b95ce 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java @@ -8,14 +8,12 @@ import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.repairables.RepairableFactory; import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.skills.SkillUtils; -import com.sk89q.worldedit.InvalidItemException; -import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.objectmapping.ObjectMappingException; import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; -import java.util.*; +import java.util.ArrayList; +import java.util.List; /** * This config diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java index fa10c1564..8b5ee541a 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java @@ -8,15 +8,12 @@ import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; import com.gmail.nossr50.skills.salvage.salvageables.SalvageableFactory; import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.skills.SkillUtils; -import ninja.leaping.configurate.commented.CommentedConfigurationNode; import ninja.leaping.configurate.objectmapping.ObjectMappingException; import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; -import java.util.Set; public class SalvageConfig extends ConfigCollection { diff --git a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java index 5588647e5..3a23b19b6 100644 --- a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java +++ b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java @@ -9,9 +9,11 @@ import ninja.leaping.configurate.objectmapping.ObjectMappingException; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.*; +import org.bukkit.potion.PotionData; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.potion.PotionType; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java index 4ee736b19..e405c27f1 100755 --- a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java @@ -1,10 +1,13 @@ package com.gmail.nossr50.config.treasure; import com.gmail.nossr50.config.ConfigCollection; +import com.gmail.nossr50.config.UnsafeValueValidation; import com.gmail.nossr50.datatypes.treasure.*; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.EnchantmentUtils; import com.gmail.nossr50.util.StringUtils; +import com.google.common.reflect.TypeToken; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.configuration.ConfigurationSection; @@ -20,9 +23,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -public class TreasureConfig extends ConfigCollection { - - //private static TreasureConfig instance; +public class TreasureConfig extends ConfigCollection implements UnsafeValueValidation { public HashMap> excavationMap = new HashMap>(); @@ -35,6 +36,7 @@ public class TreasureConfig extends ConfigCollection { public TreasureConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"treasures.yml"); super(mcMMO.p.getDataFolder().getAbsoluteFile(), "treasures.yml", false, true, false); + validateEntries(); } /** @@ -62,37 +64,41 @@ public class TreasureConfig extends ConfigCollection { @Override public List validateKeys() { // Validate all the settings! - List reason = new ArrayList(); - for (String tier : config.getConfigurationSection("Enchantment_Drop_Rates").getKeys(false)) { - double totalEnchantDropRate = 0; - double totalItemDropRate = 0; + List errorMessages = new ArrayList(); + try { + for (String tier : getUserRootNode().getNode("Enchantment_Drop_Rates").getList(TypeToken.of(String.class))) { + double totalEnchantDropRate = 0; + double totalItemDropRate = 0; - for (Rarity rarity : Rarity.values()) { - double enchantDropRate = getDoubleValue("Enchantment_Drop_Rates." + tier + "." + rarity.toString()); - double itemDropRate = getDoubleValue("Item_Drop_Rates." + tier + "." + rarity.toString()); + for (Rarity rarity : Rarity.values()) { + double enchantDropRate = getDoubleValue("Enchantment_Drop_Rates." + tier + "." + rarity.toString()); + double itemDropRate = getDoubleValue("Item_Drop_Rates." + tier + "." + rarity.toString()); - if ((enchantDropRate < 0.0 || enchantDropRate > 100.0) && rarity != Rarity.RECORD) { - reason.add("The enchant drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!"); + if ((enchantDropRate < 0.0 || enchantDropRate > 100.0) && rarity != Rarity.RECORD) { + errorMessages.add("The enchant drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!"); + } + + if (itemDropRate < 0.0 || itemDropRate > 100.0) { + errorMessages.add("The item drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!"); + } + + totalEnchantDropRate += enchantDropRate; + totalItemDropRate += itemDropRate; } - if (itemDropRate < 0.0 || itemDropRate > 100.0) { - reason.add("The item drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!"); + if (totalEnchantDropRate < 0 || totalEnchantDropRate > 100.0) { + errorMessages.add("The total enchant drop rate for " + tier + " should be between 0.0 and 100.0!"); } - totalEnchantDropRate += enchantDropRate; - totalItemDropRate += itemDropRate; - } - - if (totalEnchantDropRate < 0 || totalEnchantDropRate > 100.0) { - reason.add("The total enchant drop rate for " + tier + " should be between 0.0 and 100.0!"); - } - - if (totalItemDropRate < 0 || totalItemDropRate > 100.0) { - reason.add("The total item drop rate for " + tier + " should be between 0.0 and 100.0!"); + if (totalItemDropRate < 0 || totalItemDropRate > 100.0) { + errorMessages.add("The total item drop rate for " + tier + " should be between 0.0 and 100.0!"); + } } + } catch (ObjectMappingException e) { + e.printStackTrace(); } - return noErrorsInConfig(reason); + return errorMessages; } @Override diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java index 2357c09e7..c1b016ee7 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java @@ -8,14 +8,12 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; -import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.player.NotificationManager; -import com.gmail.nossr50.util.player.UserManager; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -25,8 +23,6 @@ import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; import java.util.ArrayList; import java.util.List;