Makes sure to use the name enchantment cost internally
This commit is contained in:
parent
4be950a327
commit
7dc2228781
@ -23,9 +23,9 @@ public enum GlobalSetting {
|
|||||||
/**
|
/**
|
||||||
* The price increase for each level of each present enchantment
|
* 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
|
* Whether the cost should increase for damage taken, as opposed to increase for durability present
|
||||||
|
@ -19,7 +19,7 @@ public class GlobalSettings {
|
|||||||
|
|
||||||
private final Map<Material, Double> materialBasePrices = new HashMap<>();
|
private final Map<Material, Double> materialBasePrices = new HashMap<>();
|
||||||
private final Map<Material, Double> materialPricePerDurabilityPoints = 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<NPCSetting, Object> defaultNPCSettings = new HashMap<>();
|
||||||
private final Map<GlobalSetting, Object> globalSettings = new HashMap<>();
|
private final Map<GlobalSetting, Object> globalSettings = new HashMap<>();
|
||||||
@ -50,7 +50,7 @@ public class GlobalSettings {
|
|||||||
globalSettings.clear();
|
globalSettings.clear();
|
||||||
materialBasePrices.clear();
|
materialBasePrices.clear();
|
||||||
materialPricePerDurabilityPoints.clear();
|
materialPricePerDurabilityPoints.clear();
|
||||||
enchantmentModifiers.clear();
|
enchantmentCosts.clear();
|
||||||
|
|
||||||
//Load/Save NPC default settings
|
//Load/Save NPC default settings
|
||||||
loadDefaultNPCSettings(root);
|
loadDefaultNPCSettings(root);
|
||||||
@ -118,11 +118,11 @@ public class GlobalSettings {
|
|||||||
* @param enchantment <p>The enchantment to get the cost for</p>
|
* @param enchantment <p>The enchantment to get the cost for</p>
|
||||||
* @return <p>The cost of each enchantment level</p>
|
* @return <p>The cost of each enchantment level</p>
|
||||||
*/
|
*/
|
||||||
public double getEnchantmentModifier(Enchantment enchantment) {
|
public double getEnchantmentCost(Enchantment enchantment) {
|
||||||
if (enchantmentModifiers.containsKey(enchantment) && enchantmentModifiers.get(enchantment) != null) {
|
if (enchantmentCosts.containsKey(enchantment) && enchantmentCosts.get(enchantment) != null) {
|
||||||
return enchantmentModifiers.get(enchantment);
|
return enchantmentCosts.get(enchantment);
|
||||||
} else {
|
} else {
|
||||||
return asDouble(GlobalSetting.ENCHANTMENT_MODIFIER);
|
return asDouble(GlobalSetting.ENCHANTMENT_COST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,13 +222,13 @@ public class GlobalSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Load all enchantment prices
|
//Load all enchantment prices
|
||||||
DataKey enchantmentModifiersNode = root.getRelative(GlobalSetting.ENCHANTMENT_MODIFIER.getParent());
|
DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent());
|
||||||
relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
||||||
for (String key : relevantKeys.keySet()) {
|
for (String key : relevantKeys.keySet()) {
|
||||||
String enchantmentName = relevantKeys.get(key);
|
String enchantmentName = relevantKeys.get(key);
|
||||||
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantmentName));
|
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantmentName));
|
||||||
if (enchantment != null) {
|
if (enchantment != null) {
|
||||||
enchantmentModifiers.put(enchantment, enchantmentModifiersNode.getDouble(key));
|
enchantmentCosts.put(enchantment, enchantmentCostNode.getDouble(key));
|
||||||
} else {
|
} else {
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
|
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING,
|
||||||
"Unable to find an enchantment matching " + enchantmentName);
|
"Unable to find an enchantment matching " + enchantmentName);
|
||||||
|
@ -147,7 +147,7 @@ public class EconomyManager {
|
|||||||
GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings();
|
GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings();
|
||||||
double price = 0;
|
double price = 0;
|
||||||
for (Enchantment enchantment : item.getEnchantments().keySet()) {
|
for (Enchantment enchantment : item.getEnchantments().keySet()) {
|
||||||
price += settings.getEnchantmentModifier(enchantment) * item.getEnchantmentLevel(enchantment);
|
price += settings.getEnchantmentCost(enchantment) * item.getEnchantmentLevel(enchantment);
|
||||||
}
|
}
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user