Fixes the handling of calculating durability
This commit is contained in:
parent
049b2c89d7
commit
a65a58fb10
@ -174,7 +174,7 @@ public class BlacksmithPlugin extends JavaPlugin {
|
|||||||
hyperPrice = to.getSellPrice(1);
|
hyperPrice = to.getSellPrice(1);
|
||||||
}
|
}
|
||||||
double hyperPricePerDurability = hyperPrice / item.getType().getMaxDurability();
|
double hyperPricePerDurability = hyperPrice / item.getType().getMaxDurability();
|
||||||
price += (((Damageable) item).getDamage() * hyperPricePerDurability);
|
price += getDurability(item) * hyperPricePerDurability;
|
||||||
|
|
||||||
double enchantmentModifier = Setting.ENCHANTMENT_MODIFIER.asDouble();
|
double enchantmentModifier = Setting.ENCHANTMENT_MODIFIER.asDouble();
|
||||||
for (Enchantment enchantment : item2.getEnchantments().keySet()) {
|
for (Enchantment enchantment : item2.getEnchantments().keySet()) {
|
||||||
@ -189,9 +189,9 @@ public class BlacksmithPlugin extends JavaPlugin {
|
|||||||
return price;
|
return price;
|
||||||
} else {
|
} else {
|
||||||
if (root.keyExists("price-per-durability-point." + item.getType().name().toLowerCase().replace('_', '-'))) {
|
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 {
|
} 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;
|
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
|
// Damage the item
|
||||||
short durability = (short) (((Damageable) reforge).getDamage() + ((Damageable) reforge).getDamage() *
|
short reforgeDurability = BlacksmithPlugin.getDurability(reforge);
|
||||||
random.nextInt(8));
|
short durability = (short) (reforgeDurability + reforgeDurability * random.nextInt(8));
|
||||||
short maxDurability = reforge.getType().getMaxDurability();
|
short maxDurability = reforge.getType().getMaxDurability();
|
||||||
if (durability <= 0) {
|
if (durability <= 0) {
|
||||||
durability = (short) (maxDurability / 3);
|
durability = (short) (maxDurability / 3);
|
||||||
} else if (((Damageable) reforge).getDamage() + durability > maxDurability) {
|
} else if (reforgeDurability + durability > maxDurability) {
|
||||||
durability = (short) (maxDurability - random.nextInt(maxDurability - 25));
|
durability = (short) (maxDurability - random.nextInt(maxDurability - 25));
|
||||||
}
|
}
|
||||||
((Damageable) reforge).setDamage(durability);
|
((Damageable) reforge.getItemMeta()).setDamage(durability);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
((Damageable) reforge).setDamage((short) 0);
|
((Damageable) reforge.getItemMeta()).setDamage((short) 0);
|
||||||
|
|
||||||
// Add random enchantments
|
// Add random enchantments
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user