Use Minecraft 'last played' for claim expirations.
This is a logout timestamp instead of a login timestamp, which is what GP records.
This commit is contained in:
parent
faee4efbef
commit
f935806b45
|
|
@ -19,6 +19,7 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
//asynchronously loads player data without caching it in the datastore, then
|
||||
//passes those data to a claim cleanup task which might decide to delete a claim for inactivity
|
||||
|
|
@ -37,6 +38,7 @@ class CleanupUnusedClaimPreTask implements Runnable
|
|||
{
|
||||
//get the data
|
||||
PlayerData ownerData = GriefPrevention.instance.dataStore.getPlayerDataFromStorage(claim.ownerID);
|
||||
OfflinePlayer ownerInfo = Bukkit.getServer().getOfflinePlayer(claim.ownerID);
|
||||
|
||||
GriefPrevention.AddLogEntry("Looking for expired claims. Checking data for " + claim.ownerID.toString(), CustomLogEntryTypes.Debug, true);
|
||||
|
||||
|
|
@ -49,6 +51,6 @@ class CleanupUnusedClaimPreTask implements Runnable
|
|||
}
|
||||
|
||||
//pass it back to the main server thread, where it's safe to delete a claim if needed
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, new CleanupUnusedClaimTask(claim, ownerData), 1L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, new CleanupUnusedClaimTask(claim, ownerData, ownerInfo), 1L);
|
||||
}
|
||||
}
|
||||
|
|
@ -19,9 +19,11 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
|
||||
|
||||
|
|
@ -29,17 +31,19 @@ class CleanupUnusedClaimTask implements Runnable
|
|||
{
|
||||
Claim claim;
|
||||
PlayerData ownerData;
|
||||
OfflinePlayer ownerInfo;
|
||||
|
||||
CleanupUnusedClaimTask(Claim claim, PlayerData ownerData)
|
||||
CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo)
|
||||
{
|
||||
this.claim = claim;
|
||||
this.ownerData = ownerData;
|
||||
this.ownerInfo = ownerInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//see if any other plugins don't want this claim deleted
|
||||
//see if any other plugins don't want this claim deleted
|
||||
ClaimExpirationEvent event = new ClaimExpirationEvent(this.claim);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(event.isCancelled()) return;
|
||||
|
|
@ -57,7 +61,7 @@ class CleanupUnusedClaimTask implements Runnable
|
|||
//if the owner has been gone at least a week, and if he has ONLY the new player claim, it will be removed
|
||||
Calendar sevenDaysAgo = Calendar.getInstance();
|
||||
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_chestClaimExpirationDays);
|
||||
boolean newPlayerClaimsExpired = sevenDaysAgo.getTime().after(ownerData.getLastLogin());
|
||||
boolean newPlayerClaimsExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed()));
|
||||
if(newPlayerClaimsExpired && ownerData.getClaims().size() == 1)
|
||||
{
|
||||
claim.removeSurfaceFluids(null);
|
||||
|
|
@ -79,7 +83,7 @@ class CleanupUnusedClaimTask implements Runnable
|
|||
Calendar earliestPermissibleLastLogin = Calendar.getInstance();
|
||||
earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays);
|
||||
|
||||
if(earliestPermissibleLastLogin.getTime().after(ownerData.getLastLogin()))
|
||||
if(earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())))
|
||||
{
|
||||
//make a copy of this player's claim list
|
||||
Vector<Claim> claims = new Vector<Claim>();
|
||||
|
|
@ -118,7 +122,7 @@ class CleanupUnusedClaimTask implements Runnable
|
|||
//if the owner has been gone at least a week, and if he has ONLY the new player claim, it will be removed
|
||||
Calendar sevenDaysAgo = Calendar.getInstance();
|
||||
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_unusedClaimExpirationDays);
|
||||
boolean claimExpired = sevenDaysAgo.getTime().after(ownerData.getLastLogin());
|
||||
boolean claimExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed()));
|
||||
if(claimExpired)
|
||||
{
|
||||
GriefPrevention.instance.dataStore.deleteClaim(claim, true, true);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user