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:
ryanhamshire 2016-04-15 21:16:33 -07:00
parent faee4efbef
commit f935806b45
2 changed files with 12 additions and 6 deletions

View File

@ -19,6 +19,7 @@
package me.ryanhamshire.GriefPrevention; package me.ryanhamshire.GriefPrevention;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
//asynchronously loads player data without caching it in the datastore, then //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 //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 //get the data
PlayerData ownerData = GriefPrevention.instance.dataStore.getPlayerDataFromStorage(claim.ownerID); 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); 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 //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);
} }
} }

View File

@ -19,9 +19,11 @@
package me.ryanhamshire.GriefPrevention; package me.ryanhamshire.GriefPrevention;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.Vector; import java.util.Vector;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
@ -29,17 +31,19 @@ class CleanupUnusedClaimTask implements Runnable
{ {
Claim claim; Claim claim;
PlayerData ownerData; PlayerData ownerData;
OfflinePlayer ownerInfo;
CleanupUnusedClaimTask(Claim claim, PlayerData ownerData) CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo)
{ {
this.claim = claim; this.claim = claim;
this.ownerData = ownerData; this.ownerData = ownerData;
this.ownerInfo = ownerInfo;
} }
@Override @Override
public void run() 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); ClaimExpirationEvent event = new ClaimExpirationEvent(this.claim);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) return; 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 //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(); Calendar sevenDaysAgo = Calendar.getInstance();
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_chestClaimExpirationDays); 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) if(newPlayerClaimsExpired && ownerData.getClaims().size() == 1)
{ {
claim.removeSurfaceFluids(null); claim.removeSurfaceFluids(null);
@ -79,7 +83,7 @@ class CleanupUnusedClaimTask implements Runnable
Calendar earliestPermissibleLastLogin = Calendar.getInstance(); Calendar earliestPermissibleLastLogin = Calendar.getInstance();
earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays); 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 //make a copy of this player's claim list
Vector<Claim> claims = new Vector<Claim>(); 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 //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(); Calendar sevenDaysAgo = Calendar.getInstance();
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_unusedClaimExpirationDays); 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) if(claimExpired)
{ {
GriefPrevention.instance.dataStore.deleteClaim(claim, true, true); GriefPrevention.instance.dataStore.deleteClaim(claim, true, true);