mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Emulate unbreaking properly
This commit is contained in:
parent
93ea558ec3
commit
a7f69545f2
@ -1,5 +1,7 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -25,6 +27,8 @@ public class Skills {
|
||||
private final static int TIME_CONVERSION_FACTOR = 1000;
|
||||
private final static double MAX_DISTANCE_AWAY = 10.0;
|
||||
|
||||
private final static Random random = new Random();
|
||||
|
||||
/**
|
||||
* Checks to see if the cooldown for an item or ability is expired.
|
||||
*
|
||||
@ -346,10 +350,14 @@ public class Skills {
|
||||
*/
|
||||
public static void abilityDurabilityLoss(ItemStack inHand, int durabilityLoss) {
|
||||
if (Config.getInstance().getAbilitiesDamageTools()) {
|
||||
if (!inHand.containsEnchantment(Enchantment.DURABILITY)) {
|
||||
inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));
|
||||
if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
|
||||
int level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
if (random.nextInt(level + 1) > 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user