From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Cryptite Date: Mon, 1 May 2023 15:23:34 -0500 Subject: [PATCH] Add PlayerPreRespawnLocationEvent diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerPreRespawnLocationEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerPreRespawnLocationEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..b321cc19d6ca57050233339ced6c84d9f793f1b6 --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerPreRespawnLocationEvent.java @@ -0,0 +1,57 @@ +package com.destroystokyo.paper.event.player; + +import org.apache.commons.lang3.Validate; +import org.bukkit.Location; +import org.bukkit.entity.Player; +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 when a respawn event tries to determine the location of a respawn. This is called before {@link PlayerRespawnEvent} + */ +public class PlayerPreRespawnLocationEvent extends PlayerEvent { + private static final HandlerList handlers = new HandlerList(); + private Location respawnLocation; + + public PlayerPreRespawnLocationEvent(@NotNull final Player respawnPlayer) { + super(respawnPlayer); + } + + /** + * Gets the current respawn location + * + * @return Location current respawn location + */ + @Nullable + public Location getRespawnLocation() { + return this.respawnLocation; + } + + /** + * Sets the new respawn location. + * + * @param respawnLocation The exact location for the respawn.
+ * Note: If this is provided, no vanilla logic that calculates "safe" respawn locations will be done. It is up to you to ensure you are + * providing a good respawn location for a Player. + */ + 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; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +}