From 32cc947fe4e6f156ceea4f5a00500809adccb046 Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Tue, 2 Feb 2016 13:34:54 -0800 Subject: [PATCH] API: Claim expiration event. Cancellable, with GPFlags in mind. --- .../CleanupUnusedClaimTask.java | 11 ++++- .../events/ClaimExpirationEvent.java | 49 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/me/ryanhamshire/GriefPrevention/events/ClaimExpirationEvent.java diff --git a/src/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java b/src/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java index c62b386..602d730 100644 --- a/src/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java +++ b/src/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java @@ -21,6 +21,10 @@ import java.util.Calendar; import java.util.Vector; +import org.bukkit.Bukkit; + +import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; + class CleanupUnusedClaimTask implements Runnable { Claim claim; @@ -35,7 +39,12 @@ class CleanupUnusedClaimTask implements Runnable @Override public void run() { - //determine area of the default chest claim + //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; if(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius >= 0) { diff --git a/src/me/ryanhamshire/GriefPrevention/events/ClaimExpirationEvent.java b/src/me/ryanhamshire/GriefPrevention/events/ClaimExpirationEvent.java new file mode 100644 index 0000000..7c63336 --- /dev/null +++ b/src/me/ryanhamshire/GriefPrevention/events/ClaimExpirationEvent.java @@ -0,0 +1,49 @@ +package me.ryanhamshire.GriefPrevention.events; + +import me.ryanhamshire.GriefPrevention.Claim; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +//if cancelled, the claim will not be deleted +public class ClaimExpirationEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled = false; + + public static HandlerList getHandlerList() + { + return handlers; + } + + Claim claim; + + public ClaimExpirationEvent(Claim claim) + { + this.claim = claim; + } + + public Claim getClaim() + { + return this.claim; + } + + @Override + public HandlerList getHandlers() + { + return handlers; + } + + @Override + public boolean isCancelled() + { + return this.cancelled; + } + + @Override + public void setCancelled(boolean cancelled) + { + this.cancelled = cancelled; + } +} \ No newline at end of file