From b3a54e16dc90274ac04c32804df06d37bc1b6c00 Mon Sep 17 00:00:00 2001 From: RoboMWM Date: Wed, 26 Sep 2018 19:55:47 -0700 Subject: [PATCH] Only call ClaimExpirationEvent if a player's claims are actually going to be expired Fixes #380 --- .../CleanupUnusedClaimTask.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java index 824297a..502821e 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java @@ -43,10 +43,7 @@ class CleanupUnusedClaimTask implements Runnable @Override public void run() { - //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; + //determine area of the default chest claim int areaOfDefaultClaim = 0; @@ -64,6 +61,8 @@ class CleanupUnusedClaimTask implements Runnable boolean newPlayerClaimsExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed())); if(newPlayerClaimsExpired && ownerData.getClaims().size() == 1) { + if (expireEventCanceled()) + return; claim.removeSurfaceFluids(null); GriefPrevention.instance.dataStore.deleteClaim(claim, true, true); @@ -85,6 +84,8 @@ class CleanupUnusedClaimTask implements Runnable if(earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed()))) { + if (expireEventCanceled()) + return; //make a copy of this player's claim list Vector claims = new Vector(); for(int i = 0; i < ownerData.getClaims().size(); i++) @@ -125,6 +126,8 @@ class CleanupUnusedClaimTask implements Runnable boolean claimExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed())); if(claimExpired) { + if (expireEventCanceled()) + return; GriefPrevention.instance.dataStore.deleteClaim(claim, true, true); GriefPrevention.AddLogEntry("Removed " + claim.getOwnerName() + "'s unused claim @ " + GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner()), CustomLogEntryTypes.AdminActivity); @@ -134,4 +137,12 @@ class CleanupUnusedClaimTask implements Runnable } } } + + public boolean expireEventCanceled() + { + //see if any other plugins don't want this claim deleted + ClaimExpirationEvent event = new ClaimExpirationEvent(this.claim); + Bukkit.getPluginManager().callEvent(event); + return event.isCancelled(); + } }