-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new PSBreakProtectBlockEvent (#419)
* breaking protection stones now trigger PSRemoveEvent * PSBreakEvent will called if the player has broken a protectionstones. * PSBreakEvent now called in playerBreakProtection function instead of BlockBreakEvent listener * renaming PSBreakEvent to PSBreakProtectBlockEvent
- Loading branch information
Showing
2 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/dev/espi/protectionstones/event/PSBreakProtectBlockEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package dev.espi.protectionstones.event; | ||
|
||
import dev.espi.protectionstones.PSRegion; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Objects; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Event that is called when a protection stones block is removed | ||
*/ | ||
public class PSBreakProtectBlockEvent extends Event implements Cancellable { | ||
|
||
private static final HandlerList HANDLERS = new HandlerList(); | ||
|
||
private PSRegion region; | ||
private Player player; | ||
private boolean isCancelled = false; | ||
|
||
public PSBreakProtectBlockEvent(PSRegion psr, Player player) { | ||
this.region = checkNotNull(psr); | ||
this.player = player; | ||
} | ||
|
||
/** | ||
* Gets the player who triggered the event. | ||
* | ||
* @return The player. | ||
*/ | ||
public Player getPlayer() { | ||
return player; | ||
} | ||
|
||
/** | ||
* Gets the ProtectionStones item associated with the region. | ||
* | ||
* @return The ProtectionStones item. | ||
*/ | ||
public ItemStack getPSItem() { | ||
return Objects.requireNonNull(region.getTypeOptions()).createItem(); | ||
} | ||
|
||
/** | ||
* Gets the ProtectionStones region associated with the event. | ||
* | ||
* @return The ProtectionStones region. | ||
*/ | ||
public PSRegion getRegion() { | ||
return region; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return isCancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancel) { | ||
isCancelled = cancel; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public HandlerList getHandlers() { | ||
return HANDLERS; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return HANDLERS; | ||
} | ||
} |