115 lines
3.2 KiB
Diff
115 lines
3.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: lexikiq <noellekiq@gmail.com>
|
|
Date: Thu, 13 May 2021 23:55:02 -0400
|
|
Subject: [PATCH] Create PlayerUseRespawnAnchorEvent
|
|
|
|
|
|
diff --git a/src/main/java/me/lexikiq/event/player/PlayerUseRespawnAnchorEvent.java b/src/main/java/me/lexikiq/event/player/PlayerUseRespawnAnchorEvent.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..96b552fe0bd6e6507c1c4f9380cab32e725cb129
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/lexikiq/event/player/PlayerUseRespawnAnchorEvent.java
|
|
@@ -0,0 +1,102 @@
|
|
+package me.lexikiq.event.player;
|
|
+
|
|
+import org.bukkit.block.Block;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.event.Cancellable;
|
|
+import org.bukkit.event.HandlerList;
|
|
+import org.bukkit.event.player.PlayerEvent;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+/**
|
|
+ * This event is fired immediately before the result of using a respawn anchor is executed
|
|
+ */
|
|
+public class PlayerUseRespawnAnchorEvent extends PlayerEvent implements Cancellable {
|
|
+
|
|
+ /**
|
|
+ * Represents the default possible outcomes of this event.
|
|
+ */
|
|
+ public enum RespawnAnchorResult {
|
|
+ /**
|
|
+ * The player's spawn point will be set
|
|
+ */
|
|
+ SET_SPAWN,
|
|
+ /**
|
|
+ * The respawn anchor will explode due to being used outside the nether
|
|
+ */
|
|
+ EXPLODE,
|
|
+ /**
|
|
+ * The player will charge the respawn anchor
|
|
+ */
|
|
+ CHARGE
|
|
+ }
|
|
+
|
|
+ private static final HandlerList handlers = new HandlerList();
|
|
+ private final Block respawnAnchor;
|
|
+ private final RespawnAnchorResult respawnAnchorResult;
|
|
+ private boolean cancelled = false;
|
|
+
|
|
+ public PlayerUseRespawnAnchorEvent(@NotNull Player who, @NotNull Block respawnAnchor, @NotNull RespawnAnchorResult respawnAnchorResult) {
|
|
+ super(who);
|
|
+ this.respawnAnchor = respawnAnchor;
|
|
+ this.respawnAnchorResult = respawnAnchorResult;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Returns the respawn anchor block involved in this event.
|
|
+ *
|
|
+ * @return the respawn anchor block involved in this event
|
|
+ */
|
|
+ @NotNull
|
|
+ public Block getRespawnAnchor() {
|
|
+ return this.respawnAnchor;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Describes the outcome of the event.
|
|
+ *
|
|
+ * @return the respawn anchor result for the outcome of the event
|
|
+ */
|
|
+ @NotNull
|
|
+ public RespawnAnchorResult getRespawnAnchorResult() {
|
|
+ return this.respawnAnchorResult;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets the cancellation state of this event. A cancelled event will not
|
|
+ * be executed in the server, but will still pass to other plugins.
|
|
+ * <p>
|
|
+ * A positive value means the respawn anchor will not take any action, as
|
|
+ * if it had not been clicked at all.
|
|
+ *
|
|
+ * @return true if this event is cancelled
|
|
+ */
|
|
+ @Override
|
|
+ public boolean isCancelled() {
|
|
+ return cancelled;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Sets the cancellation state of this event. A canceled event will not be
|
|
+ * executed in the server, but will still pass to other plugins.
|
|
+ * <p>
|
|
+ * Canceling this event will prevent use of the respawn anchor, leaving it
|
|
+ * as thought it hadn't been clicked at all.
|
|
+ *
|
|
+ * @param cancel true if you wish to cancel this event
|
|
+ */
|
|
+ @Override
|
|
+ public void setCancelled(boolean cancel) {
|
|
+ this.cancelled = cancel;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull HandlerList getHandlers() {
|
|
+ return handlers;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return handlers;
|
|
+ }
|
|
+
|
|
+}
|