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

View File

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