Files
OldSliceMC/patches/api/0019-Add-PlayerPreRespawnEvent.patch
2024-12-29 11:13:59 -06:00

89 lines
2.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com>
Date: Sat, 28 Dec 2024 07:59:54 -0600
Subject: [PATCH] Add PlayerPreRespawnEvent
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..53b830c7a349d58b1bb8b242b3edd144c6dcbdb0
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnEvent.java
@@ -0,0 +1,76 @@
+package io.papermc.paper.event.player;
+
+import org.apache.commons.lang3.Validate;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called before a player's respawn location is determined.
+ */
+public class PlayerPreRespawnEvent extends PlayerEvent implements Cancellable {
+ private static final HandlerList handlers = new HandlerList();
+ private final PlayerRespawnEvent.RespawnReason respawnReason;
+ private Location respawnLocation;
+ private boolean cancelled;
+
+ public PlayerPreRespawnEvent(@NotNull final Player respawnPlayer, PlayerRespawnEvent.RespawnReason respawnReason) {
+ super(respawnPlayer);
+ this.respawnReason = respawnReason;
+ }
+
+ /**
+ * Gets the current respawn location
+ *
+ * @return Location current respawn location
+ */
+ @Nullable
+ public Location getRespawnLocation() {
+ return this.respawnLocation;
+ }
+
+ /**
+ * Sets the new respawn location
+ *
+ * @param respawnLocation new location for the respawn
+ */
+ public void setRespawnLocation(@NotNull Location respawnLocation) {
+ Validate.notNull(respawnLocation, "Respawn location can not be null");
+ Validate.notNull(respawnLocation.getWorld(), "Respawn world can not be null");
+
+ this.respawnLocation = respawnLocation;
+ }
+
+ /**
+ * @return Returns the reason the player was respawned.
+ */
+ public PlayerRespawnEvent.RespawnReason getRespawnReason() {
+ return respawnReason;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+}