diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-04-15 22:50:55 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-04-15 22:50:55 +0100 |
commit | d927d047650fdbc53d3993611c91d172397a77c8 (patch) | |
tree | a41d80af3d68d3466396f0cea0ff4a6a14a787ea | |
parent | 6dc2e965092afc4aea815ff473185831fcaf621c (diff) | |
download | Essentials-d927d047650fdbc53d3993611c91d172397a77c8.tar Essentials-d927d047650fdbc53d3993611c91d172397a77c8.tar.gz Essentials-d927d047650fdbc53d3993611c91d172397a77c8.tar.lz Essentials-d927d047650fdbc53d3993611c91d172397a77c8.tar.xz Essentials-d927d047650fdbc53d3993611c91d172397a77c8.zip |
New config option 'cancel-afk-on-move' - Set to false you don't use afk.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java | 47 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/ISettings.java | 10 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Settings.java | 26 | ||||
-rw-r--r-- | Essentials/src/config.yml | 5 |
4 files changed, 58 insertions, 30 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 51649a203..5cd09722a 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -72,37 +72,40 @@ public class EssentialsPlayerListener implements Listener @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerMove(final PlayerMoveEvent event) { - if (event.getFrom().getBlockX() == event.getTo().getBlockX() - && event.getFrom().getBlockZ() == event.getTo().getBlockZ() - && event.getFrom().getBlockY() == event.getTo().getBlockY()) + if ((!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers()) + || event.getFrom().getBlockX() == event.getTo().getBlockX() + && event.getFrom().getBlockZ() == event.getTo().getBlockZ() + && event.getFrom().getBlockY() == event.getTo().getBlockY()) { return; } final User user = ess.getUser(event.getPlayer()); - - if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) + if (user.isAfk()) { - final Location from = event.getFrom(); - final Location to = event.getTo().clone(); - to.setX(from.getX()); - to.setY(from.getY()); - to.setZ(from.getZ()); - try + if (ess.getSettings().getFreezeAfkPlayers()) { - event.setTo(Util.getSafeDestination(to)); + final Location from = event.getFrom(); + final Location to = event.getTo().clone(); + to.setX(from.getX()); + to.setY(from.getY()); + to.setZ(from.getZ()); + try + { + event.setTo(Util.getSafeDestination(to)); + } + catch (Exception ex) + { + event.setTo(to); + } + return; } - catch (Exception ex) + + final Location afk = user.getAfkPosition(); + if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) { - event.setTo(to); + user.updateActivity(true); } - return; - } - - final Location afk = user.getAfkPosition(); - if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) - { - user.updateActivity(true); } } @@ -346,7 +349,7 @@ public class EssentialsPlayerListener implements Listener break; case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: - if (event.getItem() != null && event.getMaterial() != Material.AIR) + if (event.getItem() != null && event.getItem().getTypeId() != Material.AIR.getId()) { final User user = ess.getUser(event.getPlayer()); if (user.hasPowerTools() && user.arePowerToolsEnabled() && usePowertools(user, event.getItem().getTypeId())) diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 2c07ccd58..8eca8f06f 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -127,7 +127,7 @@ public interface ISettings extends IConf boolean removeGodOnDisconnect(); boolean changeDisplayName(); - + boolean changePlayerListName(); boolean isPlayerCommand(String string); @@ -146,6 +146,8 @@ public interface ISettings extends IConf boolean getFreezeAfkPlayers(); + boolean cancelAfkOnMove(); + boolean areDeathMessagesEnabled(); public void setDebug(boolean debug); @@ -165,12 +167,12 @@ public interface ISettings extends IConf EventPriority getRespawnPriority(); long getTpaAcceptCancellation(); - + boolean isMetricsEnabled(); - + void setMetricsEnabled(boolean metricsEnabled); long getTeleportInvulnerability(); - + boolean isTeleportInvulnerability(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index c4b19601f..34a3fec03 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -385,6 +385,8 @@ public class Settings implements ISettings teleportInvulnerability = _isTeleportInvulnerability(); disableItemPickupWhileAfk = _getDisableItemPickupWhileAfk(); registerBackInListener = _registerBackInListener(); + cancelAfkOnMove = _cancelAfkOnMove(); + getFreezeAfkPlayers = _getFreezeAfkPlayers(); itemSpawnBl = _getItemSpawnBlacklist(); kits = _getKits(); chatFormats.clear(); @@ -654,12 +656,30 @@ public class Settings implements ISettings { return config.getLong("auto-afk-kick", -1); } + private boolean getFreezeAfkPlayers; @Override public boolean getFreezeAfkPlayers() { + return getFreezeAfkPlayers; + } + + private boolean _getFreezeAfkPlayers() + { return config.getBoolean("freeze-afk-players", false); } + private boolean cancelAfkOnMove; + + @Override + public boolean cancelAfkOnMove() + { + return cancelAfkOnMove; + } + + private boolean _cancelAfkOnMove() + { + return config.getBoolean("cancel-afk-on-move", true); + } @Override public boolean areDeathMessagesEnabled() @@ -691,20 +711,18 @@ public class Settings implements ISettings { return config.getBoolean("world-teleport-permissions", false); } - private boolean registerBackInListener; - + @Override public boolean registerBackInListener() { return registerBackInListener; } - + private boolean _registerBackInListener() { return config.getBoolean("register-back-in-listener", false); } - private boolean disableItemPickupWhileAfk; @Override diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index ad49f43b6..1ace8de29 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -272,6 +272,11 @@ freeze-afk-players: false # Enable this, when you don't want people idling in mob traps. disable-item-pickup-while-afk: true +# Should we automatically remove afk status when the player moves? +# Player will be removed from afk on chat/command reguardless of this setting. +# Disable this to reduce server lag. +cancel-afk-on-move: true + # You can disable the death messages of minecraft here death-messages: true |