Add PlayerRespawnEvent#isMissingRespawnBlock (#12422)

This commit is contained in:
David 2025-04-14 19:43:19 +02:00 committed by GitHub
parent ed322043d0
commit 6b4ad08259
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -21,6 +21,7 @@ public class PlayerRespawnEvent extends PlayerEvent {
private final boolean isBedSpawn;
private final boolean isAnchorSpawn;
private final boolean missingRespawnBlock;
private final RespawnReason respawnReason;
private final Set<RespawnFlag> respawnFlags;
private Location respawnLocation;
@ -40,16 +41,17 @@ public class PlayerRespawnEvent extends PlayerEvent {
@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, respawnReason, com.google.common.collect.ImmutableSet.builder());
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, @NotNull final RespawnReason respawnReason, @NotNull final com.google.common.collect.ImmutableSet.Builder<org.bukkit.event.player.PlayerRespawnEvent.RespawnFlag> respawnFlags) {
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();
@ -95,6 +97,19 @@ public class PlayerRespawnEvent extends PlayerEvent {
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.
*

View File

@ -491,7 +491,7 @@
}
}
@@ -914,23 +_,81 @@
@@ -914,23 +_,82 @@
}
private boolean isPvpAllowed() {
@ -550,6 +550,7 @@
+ location,
+ isBedSpawn,
+ isAnchorSpawn,
+ teleportTransition.missingRespawnBlock(),
+ respawnReason,
+ builder
+ );