mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-24 17:47:44 +01:00
DefaultKeys refactored to UnsafeValueValidation
This commit is contained in:
parent
18d8b84099
commit
83ee9ca92c
@ -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<String> validKeyErrors = validateKeys(); // Validate Keys
|
||||
|
||||
if(validKeyErrors != null && validKeyErrors.size() > 0)
|
||||
{
|
||||
for(String error : validKeyErrors)
|
||||
{
|
||||
mcMMO.p.getLogger().severe(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package com.gmail.nossr50.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is for config validation
|
||||
*/
|
||||
public interface DefaultKeys {
|
||||
List<String> validateKeys();
|
||||
}
|
@ -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<String> validateKeys();
|
||||
|
||||
/**
|
||||
* Prints all errors found when validating the config
|
||||
*/
|
||||
default void validateEntries()
|
||||
{
|
||||
/*
|
||||
* Print Errors about Keys
|
||||
*/
|
||||
|
||||
List<String> validKeyErrors = validateKeys(); // Validate Keys
|
||||
|
||||
if(validKeyErrors != null && validKeyErrors.size() > 0)
|
||||
{
|
||||
for(String error : validKeyErrors)
|
||||
{
|
||||
mcMMO.p.getLogger().severe(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<String, List<ExcavationTreasure>> excavationMap = new HashMap<String, List<ExcavationTreasure>>();
|
||||
|
||||
@ -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<String> validateKeys() {
|
||||
// Validate all the settings!
|
||||
List<String> reason = new ArrayList<String>();
|
||||
for (String tier : config.getConfigurationSection("Enchantment_Drop_Rates").getKeys(false)) {
|
||||
double totalEnchantDropRate = 0;
|
||||
double totalItemDropRate = 0;
|
||||
List<String> errorMessages = new ArrayList<String>();
|
||||
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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user