diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index 77e784dfe..41bb75015 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -162,7 +162,7 @@ public class EssentialsPlayerListener implements Listener { } } - user.updateActivityOnInteract(true); + user.updateActivityOnChat(true); user.setDisplayNick(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 2a2c4ffb9..8db783517 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -199,6 +199,8 @@ public interface ISettings extends IConf { boolean cancelAfkOnInteract(); + boolean cancelAfkOnChat(); + boolean sleepIgnoresAfkPlayers(); boolean isAfkListName(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index e01a97401..7dc88601c 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -984,6 +984,11 @@ public class Settings implements net.ess3.api.ISettings { return config.getBoolean("cancel-afk-on-interact", true); } + @Override + public boolean cancelAfkOnChat() { + return config.getBoolean("cancel-afk-on-chat", true); + } + @Override public boolean sleepIgnoresAfkPlayers() { return sleepIgnoresAfkPlayers; diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index a29fc89ad..6d399d734 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -668,6 +668,15 @@ public class User extends UserData implements Comparable, IMessageRecipien } } + public void updateActivityOnChat(final boolean broadcast) { + if (ess.getSettings().cancelAfkOnChat()) { + //Chat happens async, make sure we have a sync context + ess.scheduleSyncDelayedTask(() -> { + updateActivity(broadcast, AfkStatusChangeEvent.Cause.CHAT); + }); + } + } + public void checkActivity() { // Graceful time before the first afk check call. if (System.currentTimeMillis() - lastActivity <= 10000) { diff --git a/Essentials/src/main/java/net/ess3/api/events/AfkStatusChangeEvent.java b/Essentials/src/main/java/net/ess3/api/events/AfkStatusChangeEvent.java index ab974d607..1e4296b89 100644 --- a/Essentials/src/main/java/net/ess3/api/events/AfkStatusChangeEvent.java +++ b/Essentials/src/main/java/net/ess3/api/events/AfkStatusChangeEvent.java @@ -42,6 +42,7 @@ public class AfkStatusChangeEvent extends StatusChangeEvent { INTERACT, COMMAND, JOIN, + CHAT, QUIT, UNKNOWN } diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index 3ad7dc799..3c6749e71 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -450,6 +450,9 @@ cancel-afk-on-interact: true # Disable this to reduce server lag. cancel-afk-on-move: true +# Should we automatically remove afk status when a player sends a chat message? +cancel-afk-on-chat: true + # Should AFK players be ignored when other players are trying to sleep? # When this setting is false, players won't be able to skip the night if some players are AFK. # Users with the permission node essentials.sleepingignored will always be ignored.