Fix leave messages being sent when vanished (#5009)

This commit is contained in:
Josh Roy 2022-07-23 18:35:14 -04:00 committed by GitHub
parent 09dc49aacb
commit b135fcf086
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 2 deletions

View File

@ -260,6 +260,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
user.setGodModeEnabled(false);
}
if (user.isVanished()) {
user.setLeavingHidden(true);
user.setVanished(false);
}
user.setLogoutLocation();
@ -334,6 +335,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
user.setLastLogin(currentTime);
user.setDisplayNick();
updateCompass(user);
user.setLeavingHidden(false);
// Check for new username. If they don't want the message, let's just say it's false.
final boolean newUsername = ess.getSettings().isCustomNewUsernameMessage() && lastAccountName != null && !lastAccountName.equals(user.getBase().getName());

View File

@ -94,6 +94,15 @@ public interface IUser {
*/
boolean isHidden();
/**
* Whether the user was hidden before leaving the server.
*
* @return true if the user was hidden.
*/
boolean isLeavingHidden();
void setLeavingHidden(boolean leavingHidden);
void setHidden(boolean vanish);
boolean isGodModeEnabled();

View File

@ -68,6 +68,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
// User properties
private transient boolean vanished;
private boolean hidden = false;
private boolean leavingHidden = false;
private boolean rightClickJump = false;
private boolean invSee = false;
private boolean recipeSee = false;
@ -681,6 +682,16 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
return hidden;
}
@Override
public boolean isLeavingHidden() {
return leavingHidden;
}
@Override
public void setLeavingHidden(boolean leavingHidden) {
this.leavingHidden = leavingHidden;
}
@Override
public void setHidden(final boolean hidden) {
this.hidden = hidden;

View File

@ -120,7 +120,7 @@ public class BukkitListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVanishStatusChange(VanishStatusChangeEvent event) {
if (!jda.getSettings().isVanishFakeJoinLeave()) {
if (!jda.getSettings().isVanishFakeJoinLeave() || event.getAffected().isLeavingHidden()) {
return;
}
if (event.getValue()) {
@ -235,7 +235,7 @@ public class BukkitListener implements Listener {
}
private boolean isVanishHide(final IUser user) {
return jda.getSettings().isVanishHideMessages() && user.isHidden();
return jda.getSettings().isVanishHideMessages() && (user.isHidden() || user.isLeavingHidden());
}
private void sendDiscordMessage(final MessageType messageType, final String message) {