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) { public void updateActivity(final boolean broadcast, final AfkStatusChangeEvent.Cause cause) {
if (isAfk()) { if (isAfk()) {
setAfk(false, cause); setAfk(false, cause);
if (broadcast && !isHidden()) { if (broadcast && !isHidden() && !isAfk()) {
setDisplayNick(); setDisplayNick();
final String msg = tl("userIsNotAway", getDisplayName()); final String msg = tl("userIsNotAway", getDisplayName());
final String selfmsg = tl("userIsNotAwaySelf", 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(); final long autoafk = ess.getSettings().getAutoAfk();
if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk.auto")) { if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk.auto")) {
setAfk(true, AfkStatusChangeEvent.Cause.ACTIVITY); setAfk(true, AfkStatusChangeEvent.Cause.ACTIVITY);
if (!isHidden()) { if (isAfk() && !isHidden()) {
setDisplayNick(); setDisplayNick();
final String msg = tl("userIsAway", getDisplayName()); final String msg = tl("userIsAway", getDisplayName());
final String selfmsg = tl("userIsAwaySelf", getDisplayName()); final String selfmsg = tl("userIsAwaySelf", getDisplayName());

View File

@ -61,7 +61,14 @@ public class Commandafk extends EssentialsCommand {
user.setDisplayNick(); user.setDisplayNick();
String msg = ""; String msg = "";
String selfmsg = ""; 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()) { if (!user.isHidden()) {
msg = tl("userIsNotAway", user.getDisplayName()); msg = tl("userIsNotAway", user.getDisplayName());
selfmsg = tl("userIsNotAwaySelf", user.getDisplayName()); selfmsg = tl("userIsNotAwaySelf", user.getDisplayName());