From 141512f2f7f8dbe7e844b05244eecdc60018f7f7 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 21 Feb 2021 08:54:02 -0500 Subject: [PATCH] Fix afk message being sent when event cancelled (#3915) --- .../src/main/java/com/earth2me/essentials/User.java | 4 ++-- .../com/earth2me/essentials/commands/Commandafk.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index ca77fa215..e6eed185e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -668,7 +668,7 @@ public class User extends UserData implements Comparable, IMessageRecipien public void updateActivity(final boolean broadcast, final AfkStatusChangeEvent.Cause cause) { if (isAfk()) { setAfk(false, cause); - if (broadcast && !isHidden()) { + if (broadcast && !isHidden() && !isAfk()) { setDisplayNick(); final String msg = tl("userIsNotAway", getDisplayName()); final String selfmsg = tl("userIsNotAwaySelf", getDisplayName()); @@ -729,7 +729,7 @@ public class User extends UserData implements Comparable, IMessageRecipien final long autoafk = ess.getSettings().getAutoAfk(); if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk.auto")) { setAfk(true, AfkStatusChangeEvent.Cause.ACTIVITY); - if (!isHidden()) { + if (isAfk() && !isHidden()) { setDisplayNick(); final String msg = tl("userIsAway", getDisplayName()); final String selfmsg = tl("userIsAwaySelf", getDisplayName()); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandafk.java index c4f273586..bd72f0d64 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandafk.java @@ -61,7 +61,14 @@ public class Commandafk extends EssentialsCommand { user.setDisplayNick(); String msg = ""; String selfmsg = ""; - if (!user.toggleAfk(AfkStatusChangeEvent.Cause.COMMAND)) { + + final boolean currentStatus = user.isAfk(); + final boolean afterStatus = user.toggleAfk(AfkStatusChangeEvent.Cause.COMMAND); + if (currentStatus == afterStatus) { + return; + } + + if (!afterStatus) { if (!user.isHidden()) { msg = tl("userIsNotAway", user.getDisplayName()); selfmsg = tl("userIsNotAwaySelf", user.getDisplayName());