Implement Cancellable in ClaimModifiedEvent (#942)

- If canceled, GP stops processing the resize command (no error printed or potential overlapping claim displayed)
This commit is contained in:
Frank van der Heijden
2020-08-07 10:27:49 -07:00
committed by RoboMWM
parent a3d0aecaf0
commit 4b3852d624
3 changed files with 64 additions and 16 deletions
@@ -3,6 +3,7 @@ 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;
@@ -11,7 +12,7 @@ import org.bukkit.event.HandlerList;
* 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
public class ClaimModifiedEvent extends Event implements Cancellable
{
private static final HandlerList handlers = new HandlerList();
@@ -21,12 +22,15 @@ public class ClaimModifiedEvent extends Event
return handlers;
}
private final Claim claim;
private final Claim from;
private final Claim to;
private CommandSender modifier;
private boolean cancelled;
public ClaimModifiedEvent(Claim claim, CommandSender modifier)
public ClaimModifiedEvent(Claim from, Claim to, CommandSender modifier)
{
this.claim = claim;
this.from = from;
this.to = to;
this.modifier = modifier;
}
@@ -40,10 +44,22 @@ public class ClaimModifiedEvent extends Event
* The claim
*
* @return the claim
* @deprecated Use the {@link #getTo() getTo} method.
*/
@Deprecated
public Claim getClaim()
{
return claim;
return to;
}
public Claim getFrom()
{
return from;
}
public Claim getTo()
{
return to;
}
/**
@@ -55,4 +71,16 @@ public class ClaimModifiedEvent extends Event
{
return modifier;
}
@Override
public boolean isCancelled()
{
return cancelled;
}
@Override
public void setCancelled(boolean cancelled)
{
this.cancelled = cancelled;
}
}