Skip to content

Commit

Permalink
Correct days since last login for new players
Browse files Browse the repository at this point in the history
This stops claim inspection from showing wrong information about the number of days since a new player was last seen.

OfflinePlayer.getLastPlayed() returns an epoch milliseconds value of 0 for players who have not played before.
  • Loading branch information
nouish committed Aug 3, 2024
1 parent 5bc8760 commit fd6dd05
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
import org.bukkit.util.BlockIterator;

import java.net.InetAddress;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
Expand Down Expand Up @@ -2116,9 +2118,9 @@ else if (materialInHand == instance.config_claims_investigationTool && hand == E
{
claim = claim.parent;
}
Date lastLogin = new Date(Bukkit.getOfflinePlayer(claim.ownerID).getLastPlayed());
Date now = new Date();
long daysElapsed = (now.getTime() - lastLogin.getTime()) / (1000 * 60 * 60 * 24);
OfflinePlayer claimOwner = Bukkit.getOfflinePlayer(claim.ownerID);
Instant lastSeen = claimOwner.hasPlayedBefore() ? Instant.ofEpochMilli(claimOwner.getLastPlayed()) : Instant.now();
long daysElapsed = ChronoUnit.DAYS.between(lastSeen, Instant.now());

GriefPrevention.sendMessage(player, TextMode.Info, Messages.PlayerOfflineTime, String.valueOf(daysElapsed));

Expand Down

0 comments on commit fd6dd05

Please sign in to comment.