Displays a warning when encountering unknown materials or enchantments

This commit is contained in:
Kristian Knarvik 2022-08-08 18:45:28 +02:00
parent 9d28f89c15
commit 4be950a327

View File

@ -10,6 +10,7 @@ import org.bukkit.enchantments.Enchantment;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
/** /**
* A class which keeps track of all default NPC settings and all global settings * A class which keeps track of all default NPC settings and all global settings
@ -196,9 +197,13 @@ public class GlobalSettings {
DataKey basePriceNode = root.getRelative(GlobalSetting.BASE_PRICE.getParent()); DataKey basePriceNode = root.getRelative(GlobalSetting.BASE_PRICE.getParent());
Map<String, String> relevantKeys = getRelevantKeys(basePriceNode); Map<String, String> relevantKeys = getRelevantKeys(basePriceNode);
for (String key : relevantKeys.keySet()) { for (String key : relevantKeys.keySet()) {
Material material = Material.matchMaterial(relevantKeys.get(key)); String materialName = relevantKeys.get(key);
Material material = Material.matchMaterial(materialName);
if (material != null) { if (material != null) {
materialBasePrices.put(material, basePriceNode.getDouble(key)); materialBasePrices.put(material, basePriceNode.getDouble(key));
} else {
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
"Unable to find a material matching " + materialName);
} }
} }
@ -206,9 +211,13 @@ public class GlobalSettings {
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalSetting.PRICE_PER_DURABILITY_POINT.getParent()); DataKey basePerDurabilityPriceNode = root.getRelative(GlobalSetting.PRICE_PER_DURABILITY_POINT.getParent());
relevantKeys = getRelevantKeys(basePerDurabilityPriceNode); relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
for (String key : relevantKeys.keySet()) { for (String key : relevantKeys.keySet()) {
Material material = Material.matchMaterial(relevantKeys.get(key)); String materialName = relevantKeys.get(key);
Material material = Material.matchMaterial(materialName);
if (material != null) { if (material != null) {
materialPricePerDurabilityPoints.put(material, basePerDurabilityPriceNode.getDouble(key)); materialPricePerDurabilityPoints.put(material, basePerDurabilityPriceNode.getDouble(key));
} else {
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
"Unable to find a material matching " + materialName);
} }
} }
@ -216,9 +225,13 @@ public class GlobalSettings {
DataKey enchantmentModifiersNode = root.getRelative(GlobalSetting.ENCHANTMENT_MODIFIER.getParent()); DataKey enchantmentModifiersNode = root.getRelative(GlobalSetting.ENCHANTMENT_MODIFIER.getParent());
relevantKeys = getRelevantKeys(basePerDurabilityPriceNode); relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
for (String key : relevantKeys.keySet()) { for (String key : relevantKeys.keySet()) {
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(relevantKeys.get(key))); String enchantmentName = relevantKeys.get(key);
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantmentName));
if (enchantment != null) { if (enchantment != null) {
enchantmentModifiers.put(enchantment, enchantmentModifiersNode.getDouble(key)); enchantmentModifiers.put(enchantment, enchantmentModifiersNode.getDouble(key));
} else {
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
"Unable to find an enchantment matching " + enchantmentName);
} }
} }
} }