Config validation rewrite part 1

This commit is contained in:
nossr50
2022-01-30 15:31:52 -08:00
parent 86e7bfbf89
commit 16e90da8fd
16 changed files with 293 additions and 263 deletions

View File

@@ -30,7 +30,6 @@ public class FishingTreasureConfig extends BukkitConfig {
private FishingTreasureConfig() {
super(FILENAME);
loadKeys();
validate();
}
public static FishingTreasureConfig getInstance() {
@@ -42,8 +41,8 @@ public class FishingTreasureConfig extends BukkitConfig {
}
@Override
protected boolean validateKeys() {
// Validate all the settings!
protected void validateConfigKeys() {
//TODO: Rewrite legacy validation code
List<String> reason = new ArrayList<>();
ConfigurationSection enchantment_drop_rates = config.getConfigurationSection("Enchantment_Drop_Rates");
@@ -57,11 +56,11 @@ public class FishingTreasureConfig extends BukkitConfig {
double itemDropRate = config.getDouble("Item_Drop_Rates." + tier + "." + rarity);
if ((enchantDropRate < 0.0 || enchantDropRate > 100.0)) {
reason.add("The enchant drop rate for " + tier + " items that are " + rarity + "should be between 0.0 and 100.0!");
mcMMO.p.getLogger().warning("The enchant drop rate for " + tier + " items that are " + rarity + "should be between 0.0 and 100.0!");
}
if (itemDropRate < 0.0 || itemDropRate > 100.0) {
reason.add("The item drop rate for " + tier + " items that are " + rarity + "should be between 0.0 and 100.0!");
mcMMO.p.getLogger().warning("The item drop rate for " + tier + " items that are " + rarity + "should be between 0.0 and 100.0!");
}
totalEnchantDropRate += enchantDropRate;
@@ -69,18 +68,16 @@ public class FishingTreasureConfig extends BukkitConfig {
}
if (totalEnchantDropRate < 0 || totalEnchantDropRate > 100.0) {
reason.add("The total enchant drop rate for " + tier + " should be between 0.0 and 100.0!");
mcMMO.p.getLogger().warning("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!");
mcMMO.p.getLogger().warning("The total item drop rate for " + tier + " should be between 0.0 and 100.0!");
}
}
} else {
mcMMO.p.getLogger().warning("Your fishing treasures config is empty, is this intentional? Delete it to regenerate.");
}
return noErrorsInConfig(reason);
}
@Override
@@ -141,7 +138,7 @@ public class FishingTreasureConfig extends BukkitConfig {
short data = (treasureInfo.length == 2) ? Short.parseShort(treasureInfo[1]) : (short) config.getInt(type + "." + treasureName + ".Data");
if (material == null) {
reason.add("Cannot find matching item type in this version of MC, skipping - " + materialName);
mcMMO.p.getLogger().warning("Cannot find matching item type in this version of MC, skipping - " + materialName);
continue;
}
@@ -150,7 +147,7 @@ public class FishingTreasureConfig extends BukkitConfig {
}
if (material.isBlock() && (data > 127 || data < -128)) {
reason.add("Data of " + treasureName + " is invalid! " + data);
mcMMO.p.getLogger().warning("Data of " + treasureName + " is invalid! " + data);
}
/*
@@ -162,15 +159,15 @@ public class FishingTreasureConfig extends BukkitConfig {
int dropLevel = config.getInt(type + "." + treasureName + ".Drop_Level");
if (xp < 0) {
reason.add(treasureName + " has an invalid XP value: " + xp);
mcMMO.p.getLogger().warning(treasureName + " has an invalid XP value: " + xp);
}
if (dropChance < 0.0D) {
reason.add(treasureName + " has an invalid Drop_Chance: " + dropChance);
mcMMO.p.getLogger().warning(treasureName + " has an invalid Drop_Chance: " + dropChance);
}
if (dropLevel < 0) {
reason.add("Fishing Config: " + treasureName + " has an invalid Drop_Level: " + dropLevel);
mcMMO.p.getLogger().warning("Fishing Config: " + treasureName + " has an invalid Drop_Level: " + dropLevel);
}
/*
@@ -205,7 +202,7 @@ public class FishingTreasureConfig extends BukkitConfig {
if (materialName.contains("POTION")) {
Material mat = Material.matchMaterial(materialName);
if (mat == null) {
reason.add("Potion format for " + FILENAME + " has changed");
mcMMO.p.getLogger().warning("Potion format for " + FILENAME + " has changed");
} else {
item = new ItemStack(mat, amount, data);
PotionMeta itemMeta = (PotionMeta) item.getItemMeta();
@@ -219,7 +216,7 @@ public class FishingTreasureConfig extends BukkitConfig {
try {
potionType = PotionType.valueOf(config.getString(type + "." + treasureName + ".PotionData.PotionType", "WATER"));
} catch (IllegalArgumentException ex) {
reason.add("Invalid Potion_Type: " + config.getString(type + "." + treasureName + ".PotionData.PotionType", "WATER"));
mcMMO.p.getLogger().warning("Invalid Potion_Type: " + config.getString(type + "." + treasureName + ".PotionData.PotionType", "WATER"));
}
boolean extended = config.getBoolean(type + "." + treasureName + ".PotionData.Extended", false);
boolean upgraded = config.getBoolean(type + "." + treasureName + ".PotionData.Upgraded", false);
@@ -282,15 +279,15 @@ public class FishingTreasureConfig extends BukkitConfig {
}
if (noErrorsInConfig(reason)) {
if (isFishing) {
addFishingTreasure(rarity, new FishingTreasure(item, xp));
} else if (isShake) {
ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
//TODO: Rewrite legacy validation code
// Look into what needs to change for this
if (isFishing) {
addFishingTreasure(rarity, new FishingTreasure(item, xp));
} else if (isShake) {
ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
EntityType entityType = EntityType.valueOf(type.substring(6));
addShakeTreasure(shakeTreasure, entityType);
}
EntityType entityType = EntityType.valueOf(type.substring(6));
addShakeTreasure(shakeTreasure, entityType);
}
}
}