diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerRespawnEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerRespawnEvent.java index 7c2cec60cb..c3d9d95be5 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerRespawnEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerRespawnEvent.java @@ -14,17 +14,24 @@ public class PlayerRespawnEvent extends PlayerEvent { private Location respawnLocation; private final boolean isBedSpawn; private final boolean isAnchorSpawn; + private final RespawnReason respawnReason; @Deprecated public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn) { this(respawnPlayer, respawnLocation, isBedSpawn, false); } + @Deprecated public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn, final boolean isAnchorSpawn) { + this(respawnPlayer, respawnLocation, isBedSpawn, false, RespawnReason.PLUGIN); + } + + public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn, final boolean isAnchorSpawn, @NotNull final RespawnReason respawnReason) { super(respawnPlayer); this.respawnLocation = respawnLocation; this.isBedSpawn = isBedSpawn; this.isAnchorSpawn = isAnchorSpawn; + this.respawnReason = respawnReason; } /** @@ -67,6 +74,16 @@ public class PlayerRespawnEvent extends PlayerEvent { return isAnchorSpawn; } + /** + * Gets the reason this respawn event was called. + * + * @return the reason the event was called. + */ + @NotNull + public RespawnReason getRespawnReason() { + return respawnReason; + } + @NotNull @Override public HandlerList getHandlers() { @@ -77,4 +94,23 @@ public class PlayerRespawnEvent extends PlayerEvent { public static HandlerList getHandlerList() { return handlers; } + + /** + * An enum to specify the reason a respawn event was called. + */ + public enum RespawnReason { + + /** + * When the player dies and presses the respawn button. + */ + DEATH, + /** + * When the player exits the end through the end portal. + */ + END_PORTAL, + /** + * When a plugin respawns the player. + */ + PLUGIN; + } }