Makes sure to use the name enchantment cost internally

This commit is contained in:
Kristian Knarvik 2022-08-08 18:48:46 +02:00
parent 4be950a327
commit 7dc2228781
3 changed files with 14 additions and 14 deletions

View File

@ -23,9 +23,9 @@ public enum GlobalSetting {
/**
* The price increase for each level of each present enchantment
*
* <p>This can be specified for each possible enchantment by setting enchantment-modifiers.enchantment_name</p>
* <p>This can be specified for each possible enchantment by setting enchantment-cost.enchantment_name</p>
*/
ENCHANTMENT_MODIFIER("global.enchantment-cost.default", 5),
ENCHANTMENT_COST("global.enchantment-cost.default", 5),
/**
* Whether the cost should increase for damage taken, as opposed to increase for durability present

View File

@ -19,7 +19,7 @@ public class GlobalSettings {
private final Map<Material, Double> materialBasePrices = new HashMap<>();
private final Map<Material, Double> materialPricePerDurabilityPoints = new HashMap<>();
private final Map<Enchantment, Double> enchantmentModifiers = new HashMap<>();
private final Map<Enchantment, Double> enchantmentCosts = new HashMap<>();
private final Map<NPCSetting, Object> defaultNPCSettings = new HashMap<>();
private final Map<GlobalSetting, Object> globalSettings = new HashMap<>();
@ -50,7 +50,7 @@ public class GlobalSettings {
globalSettings.clear();
materialBasePrices.clear();
materialPricePerDurabilityPoints.clear();
enchantmentModifiers.clear();
enchantmentCosts.clear();
//Load/Save NPC default settings
loadDefaultNPCSettings(root);
@ -118,11 +118,11 @@ public class GlobalSettings {
* @param enchantment <p>The enchantment to get the cost for</p>
* @return <p>The cost of each enchantment level</p>
*/
public double getEnchantmentModifier(Enchantment enchantment) {
if (enchantmentModifiers.containsKey(enchantment) && enchantmentModifiers.get(enchantment) != null) {
return enchantmentModifiers.get(enchantment);
public double getEnchantmentCost(Enchantment enchantment) {
if (enchantmentCosts.containsKey(enchantment) && enchantmentCosts.get(enchantment) != null) {
return enchantmentCosts.get(enchantment);
} else {
return asDouble(GlobalSetting.ENCHANTMENT_MODIFIER);
return asDouble(GlobalSetting.ENCHANTMENT_COST);
}
}
@ -202,7 +202,7 @@ public class GlobalSettings {
if (material != null) {
materialBasePrices.put(material, basePriceNode.getDouble(key));
} else {
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
"Unable to find a material matching " + materialName);
}
}
@ -216,21 +216,21 @@ public class GlobalSettings {
if (material != null) {
materialPricePerDurabilityPoints.put(material, basePerDurabilityPriceNode.getDouble(key));
} else {
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
"Unable to find a material matching " + materialName);
}
}
//Load all enchantment prices
DataKey enchantmentModifiersNode = root.getRelative(GlobalSetting.ENCHANTMENT_MODIFIER.getParent());
DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent());
relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
for (String key : relevantKeys.keySet()) {
String enchantmentName = relevantKeys.get(key);
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantmentName));
if (enchantment != null) {
enchantmentModifiers.put(enchantment, enchantmentModifiersNode.getDouble(key));
enchantmentCosts.put(enchantment, enchantmentCostNode.getDouble(key));
} else {
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
"Unable to find an enchantment matching " + enchantmentName);
}
}

View File

@ -147,7 +147,7 @@ public class EconomyManager {
GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings();
double price = 0;
for (Enchantment enchantment : item.getEnchantments().keySet()) {
price += settings.getEnchantmentModifier(enchantment) * item.getEnchantmentLevel(enchantment);
price += settings.getEnchantmentCost(enchantment) * item.getEnchantmentLevel(enchantment);
}
return price;
}