SPIGOT-5217, SPIGOT-6183: Add RespawnReason to PlayerRespawnEvent

By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
Bukkit/Spigot 2023-04-10 08:26:45 +10:00
parent 43b36e446e
commit 50c3f2e6e0

View file

@ -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;
}
}