Adds a new check for items with full durability (#4)
This commit is contained in:
@ -2,12 +2,12 @@ package net.knarcraft.blacksmith.manager;
|
||||
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.GlobalSettings;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicesManager;
|
||||
|
||||
@ -72,37 +72,6 @@ public class EconomyManager {
|
||||
economy.withdrawPlayer(player, getHeldItemCost(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current durability of the given item
|
||||
*
|
||||
* @param itemStack <p>The item to get the durability of</p>
|
||||
* @return <p>The durability of the item</p>
|
||||
*/
|
||||
public static short getDurability(ItemStack itemStack) {
|
||||
Damageable damageable = (Damageable) itemStack.getItemMeta();
|
||||
int maxDurability = itemStack.getType().getMaxDurability();
|
||||
if (damageable != null) {
|
||||
return (short) (maxDurability - damageable.getDamage());
|
||||
} else {
|
||||
return (short) maxDurability;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the damage done to the given item
|
||||
*
|
||||
* @param itemStack <p>The damage done to the item</p>
|
||||
* @return <p>The damage done to the item</p>
|
||||
*/
|
||||
public static short getDamage(ItemStack itemStack) {
|
||||
Damageable damageable = (Damageable) itemStack.getItemMeta();
|
||||
if (damageable != null) {
|
||||
return (short) damageable.getDamage();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cost of the item in the given player's main hand
|
||||
*
|
||||
@ -129,10 +98,10 @@ public class EconomyManager {
|
||||
double pricePerDurabilityPoint = globalSettings.getPricePerDurabilityPoint(material);
|
||||
if (globalSettings.getUseNaturalCost()) {
|
||||
//Cost increases with damage
|
||||
price += ((double) getDamage(item)) * pricePerDurabilityPoint;
|
||||
price += ((double) ItemHelper.getDamage(item)) * pricePerDurabilityPoint;
|
||||
} else {
|
||||
//Cost decreases with damage
|
||||
price += ((double) getDurability(item)) * pricePerDurabilityPoint;
|
||||
price += ((double) ItemHelper.getDurability(item)) * pricePerDurabilityPoint;
|
||||
}
|
||||
|
||||
//Increase price for any enchantments
|
||||
|
Reference in New Issue
Block a user