Fix afk message being sent when event cancelled (#3915)

This commit is contained in:
Josh Roy 2021-02-21 08:54:02 -05:00 committed by GitHub
parent 671983724a
commit 141512f2f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -668,7 +668,7 @@ public class User extends UserData implements Comparable<User>, 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<User>, 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());

View File

@ -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());