From d7fe01579b907c5d75b5c977a630ca2421ae13fd Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 27 Jan 2019 20:00:58 -0800 Subject: [PATCH] Make sure we clean up buffs from tools --- .../nossr50/listeners/BlockListener.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index aeb3fa28a..dd76d1d41 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -449,16 +449,7 @@ public class BlockListener implements Listener { if (BlockUtils.canActivateAbilities(blockState)) { ItemStack heldItem = player.getInventory().getItemInMainHand(); - if (HiddenConfig.getInstance().useEnchantmentBuffs()) { - if ((ItemUtils.isPickaxe(heldItem) && !mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER)) || (ItemUtils.isShovel(heldItem) && !mcMMOPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER))) { - SkillUtils.removeAbilityBuff(heldItem); - } - } - else { - if ((mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) { - SkillUtils.handleAbilitySpeedDecrease(player); - } - } + cleanupAbilityTools(player, mcMMOPlayer, blockState, heldItem); if (mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) { mcMMOPlayer.checkAbilityActivation(PrimarySkillType.HERBALISM); @@ -556,4 +547,28 @@ public class BlockListener implements Listener { SoundManager.sendSound(player, block.getLocation(), SoundType.POP); } } + + @EventHandler(priority = EventPriority.MONITOR) + public void onBlockDamageCleanup(BlockDamageEvent event) { + Player player = event.getPlayer(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + BlockState blockState = event.getBlock().getState(); + + ItemStack heldItem = player.getInventory().getItemInMainHand(); + + cleanupAbilityTools(player, mcMMOPlayer, blockState, heldItem); + } + + public void cleanupAbilityTools(Player player, McMMOPlayer mcMMOPlayer, BlockState blockState, ItemStack heldItem) { + if (HiddenConfig.getInstance().useEnchantmentBuffs()) { + if ((ItemUtils.isPickaxe(heldItem) && !mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER)) || (ItemUtils.isShovel(heldItem) && !mcMMOPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER))) { + SkillUtils.removeAbilityBuff(heldItem); + } + } else { + if ((mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) { + SkillUtils.handleAbilitySpeedDecrease(player); + } + } + } + }