Don't progress playtime for vanished users (#4918)

This commit is contained in:
Josh Roy 2022-06-03 21:43:12 -04:00 committed by GitHub
parent 1c5a7e9ffb
commit 3af931740b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -92,6 +92,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
private long lastHomeConfirmationTimestamp;
private Boolean toggleShout;
private transient final List<String> signCopy = Lists.newArrayList("", "", "", "");
private transient long lastVanishTime = System.currentTimeMillis();
public User(final Player base, final IEssentials ess) {
super(base, ess);
@ -964,6 +965,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
}
}
setHidden(true);
lastVanishTime = System.currentTimeMillis();
ess.getVanishedPlayersNew().add(getName());
this.getBase().setMetadata("vanished", new FixedMetadataValue(ess, true));
if (isAuthorized("essentials.vanish.effect")) {
@ -1190,6 +1192,10 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
return isBaltopExcludeCache();
}
public long getLastVanishTime() {
return lastVanishTime;
}
@Override
public Block getTargetBlock(int maxDistance) {
final Block block;

View File

@ -1,6 +1,7 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.VersionUtil;
@ -39,9 +40,12 @@ public class Commandplaytime extends EssentialsCommand {
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_15_2_R01)) {
throw e;
}
final IUser user = getPlayer(server, sender, args, 0, true);
displayName = user.getName();
final User user = getPlayer(server, args, 0, true, true);
displayName = user.getName(); // Vanished players will have their name as their display name
playtime = Bukkit.getOfflinePlayer(user.getBase().getUniqueId()).getStatistic(PLAY_ONE_TICK);
if (user.getBase().isOnline() && user.isVanished()) {
playtime = playtime - ((System.currentTimeMillis() - user.getLastVanishTime()) / 50L);
}
}
key = "playtimeOther";
} else if (sender.isPlayer()) {