Only grab List<String> if it's a proper list

This commit is contained in:
nossr50 2019-02-26 16:15:40 -08:00
parent 4ab5e5e925
commit 049b76f651
9 changed files with 304 additions and 320 deletions

View File

@ -4,8 +4,6 @@ import com.gmail.nossr50.mcMMO;
import com.google.common.io.Files;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
import org.yaml.snakeyaml.DumperOptions;
@ -415,12 +413,16 @@ public abstract class Config implements VersionedConfig, Unload {
}
/**
* Gets a a List of type String from the Configuration file
* @param path path to the node
* @return a list of strings at the node, if null it will most likely zero initialize (empty list)
* @throws ObjectMappingException
* Returns the children of a specific node
* @param path the path to the parent node
* @return the list of children for the target parent node
*/
public List<String> getStringValueList(String... path) throws ObjectMappingException {
return userRootNode.getList(TypeToken.of(String.class));
public List<? extends ConfigurationNode> getChildren(String... path) {
return userRootNode.getNode(path).getChildrenList();
}
public List<String> getListFromNode(String... path) throws ObjectMappingException
{
return userRootNode.getNode(path).getList(TypeToken.of(String.class));
}
}

View File

@ -8,7 +8,7 @@ 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 ninja.leaping.configurate.objectmapping.ObjectMappingException;
import ninja.leaping.configurate.ConfigurationNode;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -48,27 +48,27 @@ public class RepairConfig extends ConfigCollection {
@Override
public void register() {
try {
//Grab the "keys" under the Repairables node
ArrayList<String> keys = new ArrayList<>(getStringValueList(REPAIRABLES));
ArrayList<ConfigurationNode> repairChildrenNodes = new ArrayList<>(getChildren(REPAIRABLES));
//TODO: Remove Debug
if(keys.size() <= 0) {
if(repairChildrenNodes.size() <= 0) {
mcMMO.p.getLogger().severe("DEBUG: Repair MultiConfigContainer key list is empty");
return;
}
for (String key : keys) {
for (ConfigurationNode repairNode : repairChildrenNodes) {
// Validate all the things!
List<String> errorMessages = new ArrayList<String>();
/*
* Match the name of the key to a Material constant definition
*/
Material itemMaterial = Material.matchMaterial(key);
String repairChildNodeName = repairNode.getString();
Material itemMaterial = Material.matchMaterial(repairChildNodeName);
if (itemMaterial == null) {
mcMMO.p.getLogger().severe("Repair Invalid material: " + key);
mcMMO.p.getLogger().severe("Repair Invalid material: " + repairChildNodeName);
continue;
}
@ -76,9 +76,9 @@ public class RepairConfig extends ConfigCollection {
* Determine Repair Material Type
*/
MaterialType repairMaterialType = MaterialType.OTHER;
String repairMaterialTypeString = getRepairMaterialTypeString(key);
String repairMaterialTypeString = getRepairMaterialTypeString(repairChildNodeName);
if (hasNode(REPAIRABLES, key, MATERIAL_TYPE)) {
if (hasNode(REPAIRABLES, repairChildNodeName, MATERIAL_TYPE)) {
ItemStack repairItem = new ItemStack(itemMaterial);
if (ItemUtils.isWoodTool(repairItem)) {
@ -109,40 +109,40 @@ public class RepairConfig extends ConfigCollection {
repairMaterialType = MaterialType.valueOf(repairMaterialTypeString.toUpperCase());
}
catch (IllegalArgumentException ex) {
errorMessages.add("Repair Config: " + key + " has an invalid " + MATERIAL_TYPE + " of " + repairMaterialTypeString);
errorMessages.add("Repair Config: " + repairChildNodeName + " has an invalid " + MATERIAL_TYPE + " of " + repairMaterialTypeString);
continue;
}
}
// Repair Material
String repairMaterialName = getRepairMaterialStringName(key);
String repairMaterialName = getRepairMaterialStringName(repairChildNodeName);
Material repairMaterial = (repairMaterialName == null ? repairMaterialType.getDefaultMaterial() : Material.matchMaterial(repairMaterialName));
if (repairMaterial == null) {
errorMessages.add(key + " has an invalid repair material: " + repairMaterialName);
errorMessages.add(repairChildNodeName + " has an invalid repair material: " + repairMaterialName);
}
// Maximum Durability
short maximumDurability = (itemMaterial != null ? itemMaterial.getMaxDurability() : getRepairableMaximumDurability(key));
short maximumDurability = (itemMaterial != null ? itemMaterial.getMaxDurability() : getRepairableMaximumDurability(repairChildNodeName));
if (maximumDurability <= 0) {
maximumDurability = getRepairableMaximumDurability(key);
maximumDurability = getRepairableMaximumDurability(repairChildNodeName);
}
if (maximumDurability <= 0) {
errorMessages.add("Maximum durability of " + key + " must be greater than 0!");
errorMessages.add("Maximum durability of " + repairChildNodeName + " must be greater than 0!");
}
// Item Type
ItemType repairItemType = ItemType.OTHER;
String repairItemTypeString = "";
if(hasNode(REPAIRABLES, key, ITEM_TYPE))
repairItemTypeString = getStringValue(REPAIRABLES, key, ITEM_TYPE);
if(hasNode(REPAIRABLES, repairChildNodeName, ITEM_TYPE))
repairItemTypeString = getStringValue(REPAIRABLES, repairChildNodeName, ITEM_TYPE);
else
repairItemTypeString = "OTHER";
if (!hasNode(REPAIRABLES, key, ITEM_TYPE) && itemMaterial != null) {
if (!hasNode(REPAIRABLES, repairChildNodeName, ITEM_TYPE) && itemMaterial != null) {
ItemStack repairItem = new ItemStack(itemMaterial);
if (ItemUtils.isMinecraftTool(repairItem)) {
@ -157,22 +157,22 @@ public class RepairConfig extends ConfigCollection {
repairItemType = ItemType.valueOf(repairItemTypeString);
}
catch (IllegalArgumentException ex) {
errorMessages.add(key + " has an invalid ItemType of " + repairItemTypeString);
errorMessages.add(repairChildNodeName + " has an invalid ItemType of " + repairItemTypeString);
}
}
byte repairMetadata = -1;
//Set the metadata byte
if(hasNode(REPAIRABLES, key, REPAIR_MATERIAL, METADATA))
repairMetadata = (byte) getIntValue(REPAIRABLES, key, REPAIR_MATERIAL, METADATA);
if(hasNode(REPAIRABLES, repairChildNodeName, REPAIR_MATERIAL, METADATA))
repairMetadata = (byte) getIntValue(REPAIRABLES, repairChildNodeName, REPAIR_MATERIAL, METADATA);
int minimumLevel = getIntValue(REPAIRABLES, key, MINIMUM_LEVEL);
int minimumLevel = getIntValue(REPAIRABLES, repairChildNodeName, MINIMUM_LEVEL);
double xpMultiplier = 1;
if(hasNode(REPAIRABLES, key, XP_MULTIPLIER))
xpMultiplier = getDoubleValue(REPAIRABLES, key, XP_MULTIPLIER);
if(hasNode(REPAIRABLES, repairChildNodeName, XP_MULTIPLIER))
xpMultiplier = getDoubleValue(REPAIRABLES, repairChildNodeName, XP_MULTIPLIER);
@ -181,7 +181,7 @@ public class RepairConfig extends ConfigCollection {
int minimumQuantity = SkillUtils.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), repairMaterial, repairMetadata);
if (minimumQuantity <= 0) {
minimumQuantity = getIntValue(REPAIRABLES, key, MINIMUM_QUANTITY);
minimumQuantity = getIntValue(REPAIRABLES, repairChildNodeName, MINIMUM_QUANTITY);
}
/*
@ -200,7 +200,7 @@ public class RepairConfig extends ConfigCollection {
//Validate Minimum Quantity
if (minimumQuantity <= 0) {
minimumQuantity = 2;
errorMessages.add("Minimum quantity for "+key+" in repair config should be above 0");
errorMessages.add("Minimum quantity for "+repairChildNodeName+" in repair config should be above 0");
}
Repairable repairable = RepairableFactory.getRepairable(itemMaterial, repairMaterial, repairMetadata, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier);
@ -211,9 +211,6 @@ public class RepairConfig extends ConfigCollection {
mcMMO.p.getLogger().warning(error);
}
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
private String getRepairMaterialTypeString(String key) {

View File

@ -8,7 +8,7 @@ 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.objectmapping.ObjectMappingException;
import ninja.leaping.configurate.ConfigurationNode;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -44,20 +44,19 @@ public class SalvageConfig extends ConfigCollection {
@Override
public void register() {
try {
//Grab the "keys" under the Repairables node
ArrayList<String> keys = new ArrayList<>(getStringValueList(SALVAGEABLES));
ArrayList<ConfigurationNode> salvageChildrenNodes = new ArrayList<>(getChildren(SALVAGEABLES));
for (String key : keys) {
for (ConfigurationNode salvageChildNode : salvageChildrenNodes) {
// Validate all the things!
List<String> errorMessages = new ArrayList<String>();
// ItemStack Material
Material itemMaterial = Material.matchMaterial(key);
String salvageChildNodeName = salvageChildNode.getString();
Material itemMaterial = Material.matchMaterial(salvageChildNodeName);
if (itemMaterial == null) {
errorMessages.add("Salvage Config: Invalid material - " + key);
errorMessages.add("Salvage Config: Invalid material - " + salvageChildNodeName);
continue;
}
@ -66,12 +65,12 @@ public class SalvageConfig extends ConfigCollection {
String salvageMaterialTypeString;
if(hasNode(SALVAGEABLES, key, MATERIAL_TYPE))
salvageMaterialTypeString = getStringValue(SALVAGEABLES, key, MATERIAL_TYPE);
if(hasNode(SALVAGEABLES, salvageChildNodeName, MATERIAL_TYPE))
salvageMaterialTypeString = getStringValue(SALVAGEABLES, salvageChildNodeName, MATERIAL_TYPE);
else
salvageMaterialTypeString = "OTHER";
if (!hasNode(SALVAGEABLES, key, MATERIAL_TYPE)) {
if (!hasNode(SALVAGEABLES, salvageChildNodeName, MATERIAL_TYPE)) {
ItemStack salvageItem = new ItemStack(itemMaterial);
if (ItemUtils.isWoodTool(salvageItem)) {
@ -93,16 +92,16 @@ public class SalvageConfig extends ConfigCollection {
try {
salvageMaterialType = MaterialType.valueOf(salvageMaterialTypeString.replace(" ", "_").toUpperCase());
} catch (IllegalArgumentException ex) {
errorMessages.add("Salvage Config: " + key + " has an invalid MaterialType of " + salvageMaterialTypeString);
errorMessages.add("Salvage Config: " + salvageChildNodeName + " has an invalid MaterialType of " + salvageMaterialTypeString);
}
}
// Salvage Material
String salvageMaterialName = getStringValue(SALVAGEABLES, key, SALVAGE_MATERIAL);
String salvageMaterialName = getStringValue(SALVAGEABLES, salvageChildNodeName, SALVAGE_MATERIAL);
Material salvageMaterial = (salvageMaterialName == null ? salvageMaterialType.getDefaultMaterial() : Material.matchMaterial(salvageMaterialName));
if (salvageMaterial == null) {
errorMessages.add(key + " has an invalid salvage material: " + salvageMaterialName);
errorMessages.add(salvageChildNodeName + " has an invalid salvage material: " + salvageMaterialName);
continue;
}
@ -114,12 +113,12 @@ public class SalvageConfig extends ConfigCollection {
String salvageItemTypeString;
if(hasNode(SALVAGEABLES, key, ITEM_TYPE))
salvageItemTypeString = getStringValue(SALVAGEABLES, key, ITEM_TYPE);
if(hasNode(SALVAGEABLES, salvageChildNodeName, ITEM_TYPE))
salvageItemTypeString = getStringValue(SALVAGEABLES, salvageChildNodeName, ITEM_TYPE);
else
salvageItemTypeString = "OTHER";
if (!hasNode(SALVAGEABLES, key, ITEM_TYPE)) {
if (!hasNode(SALVAGEABLES, salvageChildNodeName, ITEM_TYPE)) {
ItemStack salvageItem = new ItemStack(itemMaterial);
if (ItemUtils.isMinecraftTool(salvageItem)) {
@ -131,26 +130,26 @@ public class SalvageConfig extends ConfigCollection {
try {
salvageItemType = ItemType.valueOf(salvageItemTypeString.replace(" ", "_").toUpperCase());
} catch (IllegalArgumentException ex) {
errorMessages.add("Salvage Config: " + key + " has an invalid " + ITEM_TYPE + " of " + salvageItemTypeString);
errorMessages.add("Salvage Config: " + salvageChildNodeName + " has an invalid " + ITEM_TYPE + " of " + salvageItemTypeString);
}
}
byte salvageMetadata = -1;
if(hasNode(SALVAGEABLES, key, SALVAGE_MATERIAL, METADATA))
salvageMetadata = (byte) getIntValue(SALVAGEABLES, key, SALVAGE_MATERIAL, METADATA);
if(hasNode(SALVAGEABLES, salvageChildNodeName, SALVAGE_MATERIAL, METADATA))
salvageMetadata = (byte) getIntValue(SALVAGEABLES, salvageChildNodeName, SALVAGE_MATERIAL, METADATA);
int minimumLevel = getIntValue(SALVAGEABLES, key, MINIMUM_LEVEL);
int minimumLevel = getIntValue(SALVAGEABLES, salvageChildNodeName, MINIMUM_LEVEL);
double xpMultiplier = 1;
if(hasNode(SALVAGEABLES, key, XP_MULTIPLIER))
xpMultiplier = getDoubleValue(SALVAGEABLES, key, XP_MULTIPLIER);
if(hasNode(SALVAGEABLES, salvageChildNodeName, XP_MULTIPLIER))
xpMultiplier = getDoubleValue(SALVAGEABLES, salvageChildNodeName, XP_MULTIPLIER);
// Maximum Quantity
int maximumQuantity = SkillUtils.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), salvageMaterial, salvageMetadata);
if(hasNode(SALVAGEABLES, key, MAXIMUM_QUANTITY))
maximumQuantity = getIntValue(SALVAGEABLES, key, MAXIMUM_QUANTITY);
if(hasNode(SALVAGEABLES, salvageChildNodeName, MAXIMUM_QUANTITY))
maximumQuantity = getIntValue(SALVAGEABLES, salvageChildNodeName, MAXIMUM_QUANTITY);
/*
@ -173,10 +172,6 @@ public class SalvageConfig extends ConfigCollection {
mcMMO.p.getLogger().warning(issue);
}
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
}

View File

@ -7,7 +7,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.StringUtils;
import ninja.leaping.configurate.objectmapping.Setting;
import org.bukkit.Material;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;

View File

@ -66,7 +66,7 @@ public class ItemWeightConfig extends Config {
HashSet<Material> miscItems = new HashSet<Material>();
try {
for (String item : getStringValueList(PARTY_SHAREABLES, MISC_ITEMS)) {
for (String item : getListFromNode(PARTY_SHAREABLES, MISC_ITEMS)) {
Material material = Material.getMaterial(item.toUpperCase());
if (material != null) {

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.config.skills.alchemy;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.ConfigCollection;
import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion;
import com.gmail.nossr50.mcMMO;
@ -98,14 +97,14 @@ public class PotionConfig extends ConfigCollection {
private void loadConcoctions() {
try {
loadConcoctionsTier(concoctionsIngredientsTierOne, getStringValueList(CONCOCTIONS, TIER_ONE_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierTwo, getStringValueList(CONCOCTIONS, TIER_TWO_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierThree, getStringValueList(CONCOCTIONS, TIER_THREE_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierFour, getStringValueList(CONCOCTIONS, TIER_FOUR_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierFive, getStringValueList(CONCOCTIONS, TIER_FIVE_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierSix, getStringValueList(CONCOCTIONS, TIER_SIX_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierSeven, getStringValueList(CONCOCTIONS, TIER_SEVEN_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierEight, getStringValueList(CONCOCTIONS, TIER_EIGHT_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierOne, getListFromNode(CONCOCTIONS, TIER_ONE_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierTwo, getListFromNode(CONCOCTIONS, TIER_TWO_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierThree, getListFromNode(CONCOCTIONS, TIER_THREE_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierFour, getListFromNode(CONCOCTIONS, TIER_FOUR_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierFive, getListFromNode(CONCOCTIONS, TIER_FIVE_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierSix, getListFromNode(CONCOCTIONS, TIER_SIX_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierSeven, getListFromNode(CONCOCTIONS, TIER_SEVEN_INGREDIENTS));
loadConcoctionsTier(concoctionsIngredientsTierEight, getListFromNode(CONCOCTIONS, TIER_EIGHT_INGREDIENTS));
concoctionsIngredientsTierTwo.addAll(concoctionsIngredientsTierOne);
concoctionsIngredientsTierThree.addAll(concoctionsIngredientsTierTwo);
@ -114,15 +113,14 @@ public class PotionConfig extends ConfigCollection {
concoctionsIngredientsTierSix.addAll(concoctionsIngredientsTierFive);
concoctionsIngredientsTierSeven.addAll(concoctionsIngredientsTierSix);
concoctionsIngredientsTierEight.addAll(concoctionsIngredientsTierSeven);
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
private void loadConcoctionsTier(List<ItemStack> ingredientList, List<String> ingredientStrings) {
if (ingredientStrings != null && ingredientStrings.size() > 0) {
for (String ingredientString : ingredientStrings) {
private void loadConcoctionsTier(List<ItemStack> ingredientList, List<String> ingredients) {
if (ingredients != null && ingredients.size() > 0) {
for (String ingredientString : ingredients) {
ItemStack ingredient = loadIngredient(ingredientString);
if (ingredient != null) {
@ -140,9 +138,9 @@ public class PotionConfig extends ConfigCollection {
int pass = 0;
int fail = 0;
try {
for (String potionName : getStringValueList(POTIONS)) {
for (ConfigurationNode potionNode : getChildren(POTIONS)) {
//Grab the child node corresponding to this potion
String potionName = potionNode.getString();
AlchemyPotion potion = loadPotion(getUserRootNode().getNode(POTIONS, potionName));
if (potion != null) {
@ -154,9 +152,6 @@ public class PotionConfig extends ConfigCollection {
}
mcMMO.p.debug("Loaded " + pass + " Alchemy potions, skipped " + fail + ".");
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
/**

View File

@ -5,7 +5,6 @@ import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.datatypes.MobHealthbarType;
import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.database.UpgradeType;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.player.UniqueDataType;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;

View File

@ -2,14 +2,12 @@ package com.gmail.nossr50.party;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.datatypes.chat.ChatMode;
import com.gmail.nossr50.datatypes.database.UpgradeType;
import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.party.ItemShareType;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.party.PartyLeader;
import com.gmail.nossr50.datatypes.party.ShareMode;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyAllianceChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.skills.fishing;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.util.Misc;