mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-31 04:02:06 -07:00
Parity for respawn events (#11792)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
package com.destroystokyo.paper.event.player;
|
||||
|
||||
import io.papermc.paper.event.player.AbstractRespawnEvent;
|
||||
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.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@@ -11,36 +12,31 @@ import org.jspecify.annotations.NullMarked;
|
||||
* Fired after a player has respawned
|
||||
*/
|
||||
@NullMarked
|
||||
public class PlayerPostRespawnEvent extends PlayerEvent {
|
||||
public class PlayerPostRespawnEvent extends AbstractRespawnEvent {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final Location respawnedLocation;
|
||||
private final boolean isBedSpawn;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public PlayerPostRespawnEvent(final Player respawnPlayer, final Location respawnedLocation, final boolean isBedSpawn) {
|
||||
super(respawnPlayer);
|
||||
this.respawnedLocation = respawnedLocation;
|
||||
this.isBedSpawn = isBedSpawn;
|
||||
public PlayerPostRespawnEvent(
|
||||
final Player respawnPlayer,
|
||||
final Location respawnLocation,
|
||||
final boolean isBedSpawn,
|
||||
final boolean isAnchorSpawn,
|
||||
final boolean missingRespawnBlock,
|
||||
final PlayerRespawnEvent.RespawnReason respawnReason
|
||||
) {
|
||||
super(respawnPlayer, respawnLocation, isBedSpawn, isAnchorSpawn, missingRespawnBlock, respawnReason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the location of the respawned player
|
||||
* Returns the location of the respawned player.
|
||||
*
|
||||
* @return location of the respawned player
|
||||
* @see #getRespawnLocation()
|
||||
*/
|
||||
@ApiStatus.Obsolete
|
||||
public Location getRespawnedLocation() {
|
||||
return this.respawnedLocation.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player respawned to their bed
|
||||
*
|
||||
* @return whether the player respawned to their bed
|
||||
*/
|
||||
public boolean isBedSpawn() {
|
||||
return this.isBedSpawn;
|
||||
return super.getRespawnLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,98 @@
|
||||
package io.papermc.paper.event.player;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import java.util.Set;
|
||||
|
||||
@NullMarked
|
||||
public abstract class AbstractRespawnEvent extends PlayerEvent {
|
||||
|
||||
protected Location respawnLocation;
|
||||
private final boolean isBedSpawn;
|
||||
private final boolean isAnchorSpawn;
|
||||
private final boolean missingRespawnBlock;
|
||||
private final PlayerRespawnEvent.RespawnReason respawnReason;
|
||||
private final Set<PlayerRespawnEvent.RespawnFlag> respawnFlags;
|
||||
|
||||
protected AbstractRespawnEvent(
|
||||
final Player respawnPlayer, final Location respawnLocation, final boolean isBedSpawn,
|
||||
final boolean isAnchorSpawn, final boolean missingRespawnBlock, final PlayerRespawnEvent.RespawnReason respawnReason
|
||||
) {
|
||||
super(respawnPlayer);
|
||||
this.respawnLocation = respawnLocation;
|
||||
this.isBedSpawn = isBedSpawn;
|
||||
this.isAnchorSpawn = isAnchorSpawn;
|
||||
this.missingRespawnBlock = missingRespawnBlock;
|
||||
this.respawnReason = respawnReason;
|
||||
ImmutableSet.Builder<PlayerRespawnEvent.RespawnFlag> builder = ImmutableSet.builder();
|
||||
if (respawnReason == PlayerRespawnEvent.RespawnReason.END_PORTAL) builder.add(PlayerRespawnEvent.RespawnFlag.END_PORTAL);
|
||||
if (this.isBedSpawn) builder.add(PlayerRespawnEvent.RespawnFlag.BED_SPAWN);
|
||||
if (this.isAnchorSpawn) builder.add(PlayerRespawnEvent.RespawnFlag.ANCHOR_SPAWN);
|
||||
this.respawnFlags = builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current respawn location.
|
||||
*
|
||||
* @return the current respawn location
|
||||
*/
|
||||
public Location getRespawnLocation() {
|
||||
return this.respawnLocation.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the respawn location is the player's bed.
|
||||
*
|
||||
* @return {@code true} if the respawn location is the player's bed
|
||||
*/
|
||||
public boolean isBedSpawn() {
|
||||
return this.isBedSpawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the respawn location is the player's respawn anchor.
|
||||
*
|
||||
* @return {@code true} if the respawn location is the player's respawn anchor
|
||||
*/
|
||||
public boolean isAnchorSpawn() {
|
||||
return this.isAnchorSpawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the player is missing a valid respawn block.
|
||||
* <p>
|
||||
* This will occur if the players respawn block is obstructed,
|
||||
* or it is the first death after it was either destroyed or
|
||||
* in case of a respawn anchor, ran out of charges.
|
||||
*
|
||||
* @return whether the player is missing a valid respawn block
|
||||
*/
|
||||
public boolean isMissingRespawnBlock() {
|
||||
return this.missingRespawnBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reason this respawn event was called.
|
||||
*
|
||||
* @return the reason the event was called
|
||||
*/
|
||||
public PlayerRespawnEvent.RespawnReason getRespawnReason() {
|
||||
return this.respawnReason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the set of flags that apply to this respawn.
|
||||
*
|
||||
* @return an immutable set of the flags that apply to this respawn
|
||||
* @deprecated in favour of {@link #getRespawnReason()}/{@link #isBedSpawn}/{@link #isAnchorSpawn()}
|
||||
*/
|
||||
@Deprecated
|
||||
public @Unmodifiable Set<PlayerRespawnEvent.RespawnFlag> getRespawnFlags() {
|
||||
return this.respawnFlags;
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.event.player.AbstractRespawnEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@@ -15,17 +16,10 @@ import java.util.Set;
|
||||
* If changing player state, see {@link com.destroystokyo.paper.event.player.PlayerPostRespawnEvent}
|
||||
* because the player is "reset" between this event and that event and some changes won't persist.
|
||||
*/
|
||||
public class PlayerRespawnEvent extends PlayerEvent {
|
||||
public class PlayerRespawnEvent extends AbstractRespawnEvent {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final boolean isBedSpawn;
|
||||
private final boolean isAnchorSpawn;
|
||||
private final boolean missingRespawnBlock;
|
||||
private final RespawnReason respawnReason;
|
||||
private final Set<RespawnFlag> respawnFlags;
|
||||
private Location respawnLocation;
|
||||
|
||||
@ApiStatus.Internal
|
||||
@Deprecated(since = "1.16.1", forRemoval = true)
|
||||
public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn) {
|
||||
@@ -35,40 +29,16 @@ public class PlayerRespawnEvent extends PlayerEvent {
|
||||
@ApiStatus.Internal
|
||||
@Deprecated(since = "1.19.4", forRemoval = true)
|
||||
public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn, final boolean isAnchorSpawn) {
|
||||
this(respawnPlayer, respawnLocation, isBedSpawn, isAnchorSpawn, RespawnReason.PLUGIN);
|
||||
this(respawnPlayer, respawnLocation, isBedSpawn, isAnchorSpawn, false, RespawnReason.PLUGIN);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
@Deprecated(forRemoval = true)
|
||||
public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn, final boolean isAnchorSpawn, @NotNull final RespawnReason respawnReason) {
|
||||
this(respawnPlayer, respawnLocation, isBedSpawn, isAnchorSpawn, false, respawnReason, com.google.common.collect.ImmutableSet.builder());
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn, final boolean isAnchorSpawn, final boolean missingRespawnBlock, @NotNull final RespawnReason respawnReason, @NotNull final com.google.common.collect.ImmutableSet.Builder<org.bukkit.event.player.PlayerRespawnEvent.RespawnFlag> respawnFlags) {
|
||||
super(respawnPlayer);
|
||||
this.respawnLocation = respawnLocation;
|
||||
this.isBedSpawn = isBedSpawn;
|
||||
this.isAnchorSpawn = isAnchorSpawn;
|
||||
this.respawnReason = respawnReason;
|
||||
this.missingRespawnBlock = missingRespawnBlock;
|
||||
if (this.isBedSpawn) { respawnFlags.add(RespawnFlag.BED_SPAWN); }
|
||||
if (this.isAnchorSpawn) { respawnFlags.add(RespawnFlag.ANCHOR_SPAWN); }
|
||||
this.respawnFlags = respawnFlags.build();
|
||||
public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn, final boolean isAnchorSpawn, final boolean missingRespawnBlock, @NotNull final RespawnReason respawnReason) {
|
||||
super(respawnPlayer, respawnLocation, isBedSpawn, isAnchorSpawn, missingRespawnBlock, respawnReason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current respawn location
|
||||
*
|
||||
* @return Location current respawn location
|
||||
*/
|
||||
@NotNull
|
||||
public Location getRespawnLocation() {
|
||||
return this.respawnLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new respawn location
|
||||
* Sets the new respawn location.
|
||||
*
|
||||
* @param respawnLocation new location for the respawn
|
||||
*/
|
||||
@@ -79,57 +49,6 @@ public class PlayerRespawnEvent extends PlayerEvent {
|
||||
this.respawnLocation = respawnLocation.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the respawn location is the player's bed.
|
||||
*
|
||||
* @return {@code true} if the respawn location is the player's bed.
|
||||
*/
|
||||
public boolean isBedSpawn() {
|
||||
return this.isBedSpawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the respawn location is the player's respawn anchor.
|
||||
*
|
||||
* @return {@code true} if the respawn location is the player's respawn anchor.
|
||||
*/
|
||||
public boolean isAnchorSpawn() {
|
||||
return this.isAnchorSpawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the player is missing a valid respawn block.
|
||||
* <p>
|
||||
* This will occur if the players respawn block is obstructed,
|
||||
* or it is the first death after it was either destroyed or
|
||||
* in case of a respawn anchor, ran out of charges.
|
||||
*
|
||||
* @return whether the player is missing a valid respawn block
|
||||
*/
|
||||
public boolean isMissingRespawnBlock() {
|
||||
return this.missingRespawnBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reason this respawn event was called.
|
||||
*
|
||||
* @return the reason the event was called.
|
||||
*/
|
||||
@NotNull
|
||||
public RespawnReason getRespawnReason() {
|
||||
return this.respawnReason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of flags that apply to this respawn.
|
||||
*
|
||||
* @return an immutable set of the flags that apply to this respawn
|
||||
*/
|
||||
@NotNull
|
||||
public @Unmodifiable Set<RespawnFlag> getRespawnFlags() {
|
||||
return this.respawnFlags;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
|
Reference in New Issue
Block a user