diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-02-22 00:11:21 +0000 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-02-22 00:11:21 +0000 |
commit | 34f13ba89cdb270e42fbc0f0225e0634d80b9676 (patch) | |
tree | d265308c6734a2fbb2588514f8dbf5bf03fca546 | |
parent | 945ba6f8ab8a9d3094e61fe6ccd943638eaa792a (diff) | |
download | Essentials-34f13ba89cdb270e42fbc0f0225e0634d80b9676.tar Essentials-34f13ba89cdb270e42fbc0f0225e0634d80b9676.tar.gz Essentials-34f13ba89cdb270e42fbc0f0225e0634d80b9676.tar.lz Essentials-34f13ba89cdb270e42fbc0f0225e0634d80b9676.tar.xz Essentials-34f13ba89cdb270e42fbc0f0225e0634d80b9676.zip |
Switch powertools to use different event.
Reduce multiple triggering of powertool events.
Abort event when used with powertool.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java | 101 |
1 files changed, 56 insertions, 45 deletions
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<String> 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; + 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 (event.getAction() != Action.RIGHT_CLICK_BLOCK) + } + + private boolean usePowertools(final User user) + { + final ItemStack is = user.getItemInHand(); + int id; + if (is == null || (id = is.getTypeId()) == 0) { - return; + return false; } - - if (ess.getSettings().getUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK) + final List<String> commandList = user.getPowertool(id); + if (commandList == null || commandList.isEmpty()) { - event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation()); + 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) |