diff --git a/src/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimsTask.java b/src/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimsTask.java index 1df2d26..1b321ca 100644 --- a/src/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimsTask.java +++ b/src/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimsTask.java @@ -89,7 +89,7 @@ class CleanupUnusedClaimsTask implements Runnable if(newPlayerClaimsExpired && playerData.getClaims().size() == 1) { claim.removeSurfaceFluids(null); - GriefPrevention.instance.dataStore.deleteClaim(claim); + GriefPrevention.instance.dataStore.deleteClaim(claim, true); cleanupChunks = true; //if configured to do so, restore the land to natural @@ -147,7 +147,7 @@ class CleanupUnusedClaimsTask implements Runnable if(investmentScore < minInvestment) { - GriefPrevention.instance.dataStore.deleteClaim(claim); + GriefPrevention.instance.dataStore.deleteClaim(claim, true); GriefPrevention.AddLogEntry("Removed " + claim.getOwnerName() + "'s unused claim @ " + GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner())); //if configured to do so, restore the claim area to natural state diff --git a/src/me/ryanhamshire/GriefPrevention/DataStore.java b/src/me/ryanhamshire/GriefPrevention/DataStore.java index 4dfd154..710b3b4 100644 --- a/src/me/ryanhamshire/GriefPrevention/DataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/DataStore.java @@ -23,6 +23,8 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; +import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent; + import org.bukkit.*; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -483,7 +485,12 @@ public abstract class DataStore abstract PlayerData getPlayerDataFromStorage(UUID playerID); //deletes a claim or subdivision - synchronized public void deleteClaim(Claim claim) + synchronized public void deleteClaim(Claim claim) + { + this.deleteClaim(claim, true); + } + + synchronized void deleteClaim(Claim claim, boolean fireEvent) { //subdivisions are simple - just remove them from their parent claim and save that claim if(claim.parent != null) @@ -498,7 +505,7 @@ public abstract class DataStore //delete any children for(int j = 0; j < claim.children.size(); j++) { - this.deleteClaim(claim.children.get(j)); + this.deleteClaim(claim.children.get(j), false); } //mark as deleted so any references elsewhere can be ignored @@ -545,6 +552,12 @@ public abstract class DataStore } this.savePlayerData(claim.ownerID, ownerData); } + + if(fireEvent) + { + ClaimDeletedEvent ev = new ClaimDeletedEvent(claim); + Bukkit.getPluginManager().callEvent(ev); + } } abstract void deleteClaimFromSecondaryStorage(Claim claim); @@ -752,7 +765,7 @@ public abstract class DataStore ArrayList subdivisions = new ArrayList(claim.children); //delete the claim - this.deleteClaim(claim); + this.deleteClaim(claim, false); //re-create it at the new depth claim.lesserBoundaryCorner.setY(newDepth); @@ -985,7 +998,7 @@ public abstract class DataStore Claim claim = claimsToDelete.get(i); claim.removeSurfaceFluids(null); - this.deleteClaim(claim); + this.deleteClaim(claim, true); //if in a creative mode world, delete the claim if(GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner())) @@ -1003,7 +1016,7 @@ public abstract class DataStore ArrayList subdivisions = new ArrayList(claim.children); //remove old claim - this.deleteClaim(claim); + this.deleteClaim(claim, false); //try to create this new claim, ignoring the original when checking for overlap CreateClaimResult result = this.createClaim(claim.getLesserBoundaryCorner().getWorld(), newx1, newx2, newy1, newy2, newz1, newz2, claim.ownerID, claim.parent, claim.id, resizingPlayer); diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index f7a8f27..e72d610 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -1476,7 +1476,7 @@ public class GriefPrevention extends JavaPlugin else { claim.removeSurfaceFluids(null); - this.dataStore.deleteClaim(claim); + this.dataStore.deleteClaim(claim, true); //if in a creative mode world, /restorenature the claim if(GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner())) @@ -2001,7 +2001,7 @@ public class GriefPrevention extends JavaPlugin { //delete it claim.removeSurfaceFluids(null); - this.dataStore.deleteClaim(claim); + this.dataStore.deleteClaim(claim, true); //if in a creative mode world, restore the claim area if(GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner())) diff --git a/src/me/ryanhamshire/GriefPrevention/events/ClaimDeletedEvent.java b/src/me/ryanhamshire/GriefPrevention/events/ClaimDeletedEvent.java new file mode 100644 index 0000000..e636cbe --- /dev/null +++ b/src/me/ryanhamshire/GriefPrevention/events/ClaimDeletedEvent.java @@ -0,0 +1,45 @@ +package me.ryanhamshire.GriefPrevention.events; + +import me.ryanhamshire.GriefPrevention.Claim; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * This event gets called whenever a claim is going to be deleted. This event is + * not called when a claim is resized. + * + * @author Tux2 + * + */ +public class ClaimDeletedEvent extends Event{ + + // Custom Event Requirements + private static final HandlerList handlers = new HandlerList(); + + public static HandlerList getHandlerList() { + return handlers; + } + + private Claim claim; + + public ClaimDeletedEvent(Claim claim) { + this.claim = claim; + } + + /** + * Gets the claim to be deleted. + * + * @return + */ + public Claim getClaim() { + return claim; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} \ No newline at end of file diff --git a/src/me/ryanhamshire/GriefPrevention/events/package-info.java b/src/me/ryanhamshire/GriefPrevention/events/package-info.java new file mode 100644 index 0000000..5419224 --- /dev/null +++ b/src/me/ryanhamshire/GriefPrevention/events/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author Ryan + * + */ +package me.ryanhamshire.GriefPrevention.events; \ No newline at end of file