Add ClaimCreatedEvent and ClaimModifiedEvent (#344)
1. Claim creation event... this is fired once all the claim creation checks have been passed. It can be cancelled. It contains the claim and the creating player 2. Claim modification event - this is fired as the claim is modified - it cannot be cancelled. It contains the claim and the modifier...which can be null. Use Case: This could be used so other plugins can hook gp and perform an action if a claim is created or changed. Something as simple as logging claim creations/modifications and deletions.
This commit is contained in:
parent
31c1581ca2
commit
643ad8a7f7
|
|
@ -19,7 +19,9 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimCreatedEvent;
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent;
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimModifiedEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
|
|
@ -758,7 +760,14 @@ public abstract class DataStore
|
|||
{
|
||||
return getChunkHash(location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Creates a claim and flags it as being new....throwing a create claim event;
|
||||
*/
|
||||
synchronized public CreateClaimResult createClaim(World world, int x1, int x2, int y1, int y2, int z1, int z2, UUID ownerID, Claim parent, Long id, Player creatingPlayer)
|
||||
{
|
||||
return createClaim(world,x1,x2,y1,y2,z1,z2,ownerID,parent,id,creatingPlayer,true);
|
||||
}
|
||||
//creates a claim.
|
||||
//if the new claim would overlap an existing claim, returns a failure along with a reference to the existing claim
|
||||
//if the new claim would overlap a WorldGuard region where the player doesn't have permission to build, returns a failure with NULL for claim
|
||||
|
|
@ -770,7 +779,7 @@ public abstract class DataStore
|
|||
//does NOT check a player has permission to create a claim, or enough claim blocks.
|
||||
//does NOT check minimum claim size constraints
|
||||
//does NOT visualize the new claim for any players
|
||||
synchronized public CreateClaimResult createClaim(World world, int x1, int x2, int y1, int y2, int z1, int z2, UUID ownerID, Claim parent, Long id, Player creatingPlayer)
|
||||
synchronized public CreateClaimResult createClaim(World world, int x1, int x2, int y1, int y2, int z1, int z2, UUID ownerID, Claim parent, Long id, Player creatingPlayer, Boolean isNew)
|
||||
{
|
||||
CreateClaimResult result = new CreateClaimResult();
|
||||
|
||||
|
|
@ -866,8 +875,20 @@ public abstract class DataStore
|
|||
result.claim = null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isNew) {
|
||||
ClaimCreatedEvent event = new ClaimCreatedEvent(newClaim, creatingPlayer);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
result.succeeded = false;
|
||||
result.claim = null;
|
||||
return result;
|
||||
|
||||
}
|
||||
} else {
|
||||
ClaimModifiedEvent event = new ClaimModifiedEvent(newClaim, creatingPlayer);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
//otherwise add this new claim to the data store to make it effective
|
||||
this.addClaim(newClaim, true);
|
||||
|
||||
|
|
@ -955,6 +976,8 @@ public abstract class DataStore
|
|||
|
||||
//save changes
|
||||
this.saveClaim(claim);
|
||||
ClaimModifiedEvent event = new ClaimModifiedEvent(claim,null);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
//starts a siege on a claim
|
||||
|
|
@ -1237,7 +1260,8 @@ public abstract class DataStore
|
|||
|
||||
//save those changes
|
||||
this.saveClaim(result.claim);
|
||||
|
||||
ClaimModifiedEvent event = new ClaimModifiedEvent(result.claim,resizingPlayer);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
//make original claim ineffective (it's still in the hash map, so let's make it ignored)
|
||||
claim.inDataStore = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* This Event is thrown when a claim is created but before it is saved. If it is cancelled the claim will not be saved
|
||||
* however the player will not recieved information as to why it was cancelled.
|
||||
* <p>
|
||||
* Created by Narimm on 5/08/2018.
|
||||
*/
|
||||
|
||||
public class ClaimCreatedEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final Claim claim;
|
||||
|
||||
private final CommandSender creator;
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public ClaimCreatedEvent(Claim claim, CommandSender creator) {
|
||||
this.claim = claim;
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
this.cancelled = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Claim
|
||||
*
|
||||
* @return Claim
|
||||
*/
|
||||
public Claim getClaim() {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actor creating the claim
|
||||
*
|
||||
* @return the CommandSender
|
||||
*/
|
||||
public CommandSender getCreator() {
|
||||
return creator;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* This Event is thrown when a claim is changed....it is not modifiable or cancellable and only serves as a notification
|
||||
* a claim has changed. The CommandSender can be null in the event that the modification is called by the plugin itself.
|
||||
* Created by Narimm on 5/08/2018.
|
||||
*/
|
||||
public class ClaimModifiedEvent extends Event {
|
||||
|
||||
private final HandlerList handlers = new HandlerList();
|
||||
private final Claim claim;
|
||||
private CommandSender modifier;
|
||||
|
||||
public ClaimModifiedEvent(Claim claim, CommandSender modifier) {
|
||||
this.claim = claim;
|
||||
this.modifier = modifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* The claim
|
||||
*
|
||||
* @return the claim
|
||||
*/
|
||||
public Claim getClaim() {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actor making the change...can be null
|
||||
*
|
||||
* @return the CommandSender or null
|
||||
*/
|
||||
public CommandSender getModifier() {
|
||||
return modifier;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user