Fix tool damage not being applied

This commit is contained in:
Esophose 2019-03-30 17:22:45 -06:00
parent 120cb29c3b
commit e94a0c6259
3 changed files with 7 additions and 4 deletions

View File

@ -56,8 +56,7 @@ public class CurrentAdapter implements VersionAdapter {
@Override @Override
public void applyToolDurability(Player player, int damage) { public void applyToolDurability(Player player, int damage) {
ItemStack tool = this.getItemInHand(player); ItemStack tool = this.getItemInHand(player);
if (!(tool.getItemMeta() instanceof Damageable))
if (!tool.hasItemMeta() || !(tool.getItemMeta() instanceof Damageable))
return; return;
int unbreakingLevel = tool.getEnchantmentLevel(Enchantment.DURABILITY); int unbreakingLevel = tool.getEnchantmentLevel(Enchantment.DURABILITY);
@ -71,7 +70,8 @@ public class CurrentAdapter implements VersionAdapter {
damageable.setDamage(damageable.getDamage() + actualDamage); damageable.setDamage(damageable.getDamage() + actualDamage);
tool.setItemMeta((ItemMeta) damageable); tool.setItemMeta((ItemMeta) damageable);
if (!this.hasEnoughDurability(tool, 1))
this.removeItemInHand(player);
} }
@Override @Override

View File

@ -42,7 +42,7 @@ public class Methods {
* @return True if durability should be applied, otherwise false * @return True if durability should be applied, otherwise false
*/ */
public static boolean checkUnbreakingChance(int level) { public static boolean checkUnbreakingChance(int level) {
return ((double) 1 / (level + 1)) > random.nextDouble(); return (1.0 / (level + 1)) > random.nextDouble();
} }
} }

View File

@ -75,6 +75,9 @@ public class TreeFallManager extends Manager implements Listener {
if (detectedTree == null) if (detectedTree == null)
return; return;
if (!treeDefinitionManager.isToolValidForTreeDefinition(detectedTree.getTreeDefinition(), tool))
return;
int toolDamage = ConfigurationManager.Setting.REALISTIC_TOOL_DAMAGE.getBoolean() ? detectedTree.getDetectedTreeBlocks().getLogBlocks().size() : 1; int toolDamage = ConfigurationManager.Setting.REALISTIC_TOOL_DAMAGE.getBoolean() ? detectedTree.getDetectedTreeBlocks().getLogBlocks().size() : 1;
if (ConfigurationManager.Setting.PROTECT_TOOL.getBoolean() && !versionAdapter.hasEnoughDurability(tool, toolDamage)) if (ConfigurationManager.Setting.PROTECT_TOOL.getBoolean() && !versionAdapter.hasEnoughDurability(tool, toolDamage))
return; return;