Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClaimExtendEvent #947

Merged
merged 4 commits into from Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java
Expand Up @@ -21,6 +21,7 @@
import com.google.common.io.Files;
import me.ryanhamshire.GriefPrevention.events.ClaimCreatedEvent;
import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent;
import me.ryanhamshire.GriefPrevention.events.ClaimExtendEvent;
import me.ryanhamshire.GriefPrevention.events.ClaimModifiedEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -1039,6 +1040,11 @@ synchronized public void extendClaim(Claim claim, int newDepth)

if (claim.parent != null) claim = claim.parent;

//call event and return if event got cancelled
ClaimExtendEvent event = new ClaimExtendEvent(claim, newDepth);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) return;

//adjust to new depth
claim.lesserBoundaryCorner.setY(newDepth);
claim.greaterBoundaryCorner.setY(newDepth);
Expand Down
@@ -0,0 +1,58 @@
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;

/**
* A cancellable event which is called when a claim's depth (lower y bound) is about to be extended.
* @author FrankHeijden
*/
public class ClaimExtendEvent extends Event implements Cancellable
{
private static final HandlerList handlers = new HandlerList();

public static HandlerList getHandlerList()
{
return handlers;
}

private final Claim claim;
private final int newDepth;
private boolean cancelled;

public ClaimExtendEvent(Claim claim, int newDepth)
{
this.claim = claim;
this.newDepth = newDepth;
}

@Override
public HandlerList getHandlers()
{
return handlers;
}

public Claim getClaim()
{
return claim;
}

public int getNewDepth()
{
return newDepth;
}

@Override
public boolean isCancelled()
{
return cancelled;
}

@Override
public void setCancelled(boolean cancelled)
{
this.cancelled = cancelled;
}
}