Skip to content

Commit

Permalink
Fix issue related to unbreaking enchantments
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankTCA committed May 19, 2024
1 parent 791f5a6 commit 497c28e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main/java/org/infotoast/dropsoverhaul/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Listener implements org.bukkit.event.Listener {
public Listener(Plugin pl) {
this.pl = pl;
}
private Random rand = new Random();
@EventHandler
public void onBlockBreak(BlockBreakEvent evt) {
ItemLists lists = new ItemLists();
Expand Down Expand Up @@ -67,9 +68,7 @@ public void onBlockBreak(BlockBreakEvent evt) {
blocc.setType(Material.AIR, true);
if (lists.isTool(breaker.getInventory().getItemInMainHand().getType()))
if (breaker.getInventory().getItemInMainHand().getItemMeta() instanceof Damageable) {
if (breaker.getInventory().getItemInMainHand().containsEnchantment(Enchantment.UNBREAKING) && new Random().nextInt(breaker.getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.UNBREAKING) + 1) != 0)
breaker.getInventory().getItemInMainHand().setDurability((short)(((Damageable)breaker.getInventory().getItemInMainHand().getItemMeta()).getDamage() + 1));
else
if (!(breaker.getInventory().getItemInMainHand().containsEnchantment(Enchantment.UNBREAKING) && rand.nextInt(100) > (100 / (breaker.getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.UNBREAKING) + 1))))
breaker.getInventory().getItemInMainHand().setDurability((short)(((Damageable)breaker.getInventory().getItemInMainHand().getItemMeta()).getDamage() + 1));
if (breaker.getInventory().getItemInMainHand().getDurability() >= breaker.getInventory().getItemInMainHand().getType().getMaxDurability() && breaker.getInventory().getItemInMainHand().getType().getMaxDurability() > 0)
breaker.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
Expand Down

0 comments on commit 497c28e

Please sign in to comment.