From f21fbe2d40f3e6ba37769516cdccc7f0eecbdc10 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 21 May 2013 22:34:06 -0400 Subject: [PATCH] Make repair & salvage respect the sneaking settings. Fixes #1108 --- .../nossr50/listeners/PlayerListener.java | 68 ++++++++++--------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 0bb510f1c..ea0dac100 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -343,26 +343,28 @@ public class PlayerListener implements Listener { case RIGHT_CLICK_BLOCK: int blockID = block.getTypeId(); - /* REPAIR CHECKS */ - if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) { - RepairManager repairManager = mcMMOPlayer.getRepairManager(); - event.setCancelled(true); + if ((Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && player.isSneaking()) || !Config.getInstance().getAbilitiesOnlyActivateWhenSneaking()) { + /* REPAIR CHECKS */ + if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) { + RepairManager repairManager = mcMMOPlayer.getRepairManager(); + event.setCancelled(true); - // Make sure the player knows what he's doing when trying to repair an enchanted item - if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) { - repairManager.handleRepair(heldItem); - player.updateInventory(); + // Make sure the player knows what he's doing when trying to repair an enchanted item + if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) { + repairManager.handleRepair(heldItem); + player.updateInventory(); + } } - } - /* SALVAGE CHECKS */ - else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem) && !ItemUtils.isChainmailArmor(heldItem)) { - RepairManager repairManager = mcMMOPlayer.getRepairManager(); - event.setCancelled(true); + /* SALVAGE CHECKS */ + else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem) && !ItemUtils.isChainmailArmor(heldItem)) { + RepairManager repairManager = mcMMOPlayer.getRepairManager(); + event.setCancelled(true); - // Make sure the player knows what he's doing when trying to salvage an enchanted item - if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) { - repairManager.handleSalvage(block.getLocation(), heldItem); - player.updateInventory(); + // Make sure the player knows what he's doing when trying to salvage an enchanted item + if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) { + repairManager.handleSalvage(block.getLocation(), heldItem); + player.updateInventory(); + } } } /* BLAST MINING CHECK */ @@ -380,24 +382,26 @@ public class PlayerListener implements Listener { case LEFT_CLICK_BLOCK: blockID = block.getTypeId(); - /* REPAIR CHECKS */ - if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) { - RepairManager repairManager = mcMMOPlayer.getRepairManager(); + if ((Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && player.isSneaking()) || !Config.getInstance().getAbilitiesOnlyActivateWhenSneaking()) { + /* REPAIR CHECKS */ + if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) { + RepairManager repairManager = mcMMOPlayer.getRepairManager(); - // Cancel repairing an enchanted item - if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) { - mcMMOPlayer.setLastAnvilUse(Repair.repairAnvilId, 0); - player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Repair.Pretty.Name"))); + // Cancel repairing an enchanted item + if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) { + mcMMOPlayer.setLastAnvilUse(Repair.repairAnvilId, 0); + player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Repair.Pretty.Name"))); + } } - } - /* SALVAGE CHECKS */ - else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) { - RepairManager repairManager = mcMMOPlayer.getRepairManager(); + /* SALVAGE CHECKS */ + else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) { + RepairManager repairManager = mcMMOPlayer.getRepairManager(); - // Cancel salvaging an enchanted item - if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) { - mcMMOPlayer.setLastAnvilUse(Repair.salvageAnvilId, 0); - player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Salvage.Pretty.Name"))); + // Cancel salvaging an enchanted item + if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) { + mcMMOPlayer.setLastAnvilUse(Repair.salvageAnvilId, 0); + player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Salvage.Pretty.Name"))); + } } }