Fixes the handling of calculating durability
This commit is contained in:
		@@ -174,7 +174,7 @@ public class BlacksmithPlugin extends JavaPlugin {
 | 
			
		||||
                hyperPrice = to.getSellPrice(1);
 | 
			
		||||
            }
 | 
			
		||||
            double hyperPricePerDurability = hyperPrice / item.getType().getMaxDurability();
 | 
			
		||||
            price += (((Damageable) item).getDamage() * hyperPricePerDurability);
 | 
			
		||||
            price += getDurability(item) * hyperPricePerDurability;
 | 
			
		||||
 | 
			
		||||
            double enchantmentModifier = Setting.ENCHANTMENT_MODIFIER.asDouble();
 | 
			
		||||
            for (Enchantment enchantment : item2.getEnchantments().keySet()) {
 | 
			
		||||
@@ -189,9 +189,9 @@ public class BlacksmithPlugin extends JavaPlugin {
 | 
			
		||||
            return price;
 | 
			
		||||
        } else {
 | 
			
		||||
            if (root.keyExists("price-per-durability-point." + item.getType().name().toLowerCase().replace('_', '-'))) {
 | 
			
		||||
                price += ((Damageable) item).getDamage() * root.getDouble("price-per-durability-point." + item.getType().name().toLowerCase().replace('_', '-'));
 | 
			
		||||
                price += getDurability(item) * root.getDouble("price-per-durability-point." + item.getType().name().toLowerCase().replace('_', '-'));
 | 
			
		||||
            } else {
 | 
			
		||||
                price += (((Damageable) item).getDamage() * Setting.PRICE_PER_DURABILITY_POINT.asDouble());
 | 
			
		||||
                price += getDurability(item) * Setting.PRICE_PER_DURABILITY_POINT.asDouble();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -205,4 +205,16 @@ public class BlacksmithPlugin extends JavaPlugin {
 | 
			
		||||
        }
 | 
			
		||||
        return price;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the durability of the given item
 | 
			
		||||
     *
 | 
			
		||||
     * @param itemStack <p>The item to get the durability of</p>
 | 
			
		||||
     * @return <p>The durability of the item</p>
 | 
			
		||||
     */
 | 
			
		||||
    static short getDurability(ItemStack itemStack) {
 | 
			
		||||
        Damageable damageable = (Damageable) itemStack.getItemMeta();
 | 
			
		||||
        return (short) (itemStack.getType().getMaxDurability() - damageable.getDamage());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -291,19 +291,19 @@ public class BlacksmithTrait extends Trait {
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                // Damage the item
 | 
			
		||||
                short durability = (short) (((Damageable) reforge).getDamage() + ((Damageable) reforge).getDamage() *
 | 
			
		||||
                        random.nextInt(8));
 | 
			
		||||
                short reforgeDurability = BlacksmithPlugin.getDurability(reforge);
 | 
			
		||||
                short durability = (short) (reforgeDurability + reforgeDurability * random.nextInt(8));
 | 
			
		||||
                short maxDurability = reforge.getType().getMaxDurability();
 | 
			
		||||
                if (durability <= 0) {
 | 
			
		||||
                    durability = (short) (maxDurability / 3);
 | 
			
		||||
                } else if (((Damageable) reforge).getDamage() + durability > maxDurability) {
 | 
			
		||||
                } else if (reforgeDurability + durability > maxDurability) {
 | 
			
		||||
                    durability = (short) (maxDurability - random.nextInt(maxDurability - 25));
 | 
			
		||||
                }
 | 
			
		||||
                ((Damageable) reforge).setDamage(durability);
 | 
			
		||||
                ((Damageable) reforge.getItemMeta()).setDamage(durability);
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            ((Damageable) reforge).setDamage((short) 0);
 | 
			
		||||
            ((Damageable) reforge.getItemMeta()).setDamage((short) 0);
 | 
			
		||||
 | 
			
		||||
            // Add random enchantments
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user