diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 8e151c3e9..a3b4559a2 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -282,44 +282,6 @@ public class EssentialsPlayerListener implements Listener { final User user = ess.getUser(event.getPlayer()); user.updateActivity(true); - if (event.getAnimationType() == PlayerAnimationType.ARM_SWING - && user.hasPowerTools() && user.arePowerToolsEnabled()) - { - usePowertools(user); - } - } - - private void usePowertools(final User user) - { - final ItemStack is = user.getItemInHand(); - int id; - if (is == null || (id = is.getTypeId()) == 0) - { - return; - } - final List commandList = user.getPowertool(id); - if (commandList == null || commandList.isEmpty()) - { - return; - } - - // We need to loop through each command and execute - for (String command : commandList) - { - if (command.matches(".*\\{player\\}.*")) - { - //user.sendMessage("Click a player to use this command"); - continue; - } - else if (command.startsWith("c:")) - { - user.chat(command.substring(2)); - } - else - { - user.getServer().dispatchCommand(user.getBase(), command); - } - } } @EventHandler(priority = EventPriority.MONITOR) @@ -365,19 +327,68 @@ public class EssentialsPlayerListener implements Listener @EventHandler(priority = EventPriority.MONITOR) public void onPlayerInteract(final PlayerInteractEvent event) { - if (event.isCancelled()) + switch (event.getAction()) { - return; - } - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) - { - return; + case RIGHT_CLICK_BLOCK: + if (event.isCancelled()) + { + return; + } + if (ess.getSettings().getUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK) + { + event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation()); + } + break; + case LEFT_CLICK_AIR: + case LEFT_CLICK_BLOCK: + final User user = ess.getUser(event.getPlayer()); + if (user.hasPowerTools() && user.arePowerToolsEnabled()) + { + if (usePowertools(user)) + { + event.setCancelled(true); + } + } + break; + default: + break; } + } - if (ess.getSettings().getUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK) + private boolean usePowertools(final User user) + { + final ItemStack is = user.getItemInHand(); + int id; + if (is == null || (id = is.getTypeId()) == 0) { - event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation()); + return false; } + final List commandList = user.getPowertool(id); + if (commandList == null || commandList.isEmpty()) + { + return false; + } + boolean used = false; + // We need to loop through each command and execute + for (String command : commandList) + { + if (command.matches(".*\\{player\\}.*")) + { + //user.sendMessage("Click a player to use this command"); + continue; + } + else if (command.startsWith("c:")) + { + used = true; + user.chat(command.substring(2)); + } + else + { + used = true; + user.getServer().dispatchCommand(user.getBase(), command); + } + } + return used; } @EventHandler(priority = EventPriority.LOW)