Fixed unbreakable bugs

This commit is contained in:
Auxilor 2021-08-13 13:29:08 +01:00
parent e3d55dfbe6
commit ef5fcc8869
2 changed files with 17 additions and 10 deletions

View File

@ -83,9 +83,11 @@ public class BlastMining extends EcoEnchant {
}
}
}
ItemStack itemStack = player.getInventory().getItemInMainHand();
ItemMeta beforeMeta = itemStack.getItemMeta();
assert beforeMeta != null;
boolean hadUnbreak = beforeMeta.isUnbreakable();
beforeMeta.setUnbreakable(true);
itemStack.setItemMeta(beforeMeta);
int blocks = toBreak.size();
@ -98,15 +100,17 @@ public class BlastMining extends EcoEnchant {
ItemMeta afterMeta = itemStack.getItemMeta();
assert afterMeta != null;
afterMeta.setUnbreakable(false);
afterMeta.setUnbreakable(hadUnbreak);
itemStack.setItemMeta(afterMeta);
PlayerItemDamageEvent mockEvent = new PlayerItemDamageEvent(player, itemStack, blocks);
Bukkit.getPluginManager().callEvent(mockEvent);
ItemMeta wayAfterMeta = itemStack.getItemMeta();
assert wayAfterMeta != null;
((Damageable) wayAfterMeta).setDamage(((Damageable) wayAfterMeta).getDamage() + mockEvent.getDamage());
itemStack.setItemMeta(wayAfterMeta);
if (!hadUnbreak) {
ItemMeta wayAfterMeta = itemStack.getItemMeta();
assert wayAfterMeta != null;
((Damageable) wayAfterMeta).setDamage(((Damageable) wayAfterMeta).getDamage() + mockEvent.getDamage());
itemStack.setItemMeta(wayAfterMeta);
}
AnticheatManager.unexemptPlayer(player);
}

View File

@ -58,6 +58,7 @@ public class Lumberjack extends EcoEnchant {
ItemStack itemStack = player.getInventory().getItemInMainHand();
ItemMeta beforeMeta = itemStack.getItemMeta();
assert beforeMeta != null;
boolean hadUnbreak = beforeMeta.isUnbreakable();
beforeMeta.setUnbreakable(true);
itemStack.setItemMeta(beforeMeta);
int blocks = treeBlocks.size();
@ -75,15 +76,17 @@ public class Lumberjack extends EcoEnchant {
ItemMeta afterMeta = itemStack.getItemMeta();
assert afterMeta != null;
afterMeta.setUnbreakable(false);
afterMeta.setUnbreakable(hadUnbreak);
itemStack.setItemMeta(afterMeta);
PlayerItemDamageEvent mockEvent = new PlayerItemDamageEvent(player, itemStack, blocks);
Bukkit.getPluginManager().callEvent(mockEvent);
ItemMeta wayAfterMeta = itemStack.getItemMeta();
assert wayAfterMeta != null;
((Damageable) wayAfterMeta).setDamage(((Damageable) wayAfterMeta).getDamage() + mockEvent.getDamage());
itemStack.setItemMeta(wayAfterMeta);
if (!hadUnbreak) {
ItemMeta wayAfterMeta = itemStack.getItemMeta();
assert wayAfterMeta != null;
((Damageable) wayAfterMeta).setDamage(((Damageable) wayAfterMeta).getDamage() + mockEvent.getDamage());
itemStack.setItemMeta(wayAfterMeta);
}
AnticheatManager.unexemptPlayer(player);
}