Add PlayerRespawnEvent#isMissingRespawnBlock (#12422)

This commit is contained in:
David
2025-04-17 19:52:07 +01:00
committed by Shane Freeder
parent 0767902699
commit a838a886dc
3 changed files with 45 additions and 10 deletions

View File

@@ -18,8 +18,9 @@ public class PlayerRespawnEvent extends PlayerEvent {
private Location respawnLocation; private Location respawnLocation;
private final boolean isBedSpawn; private final boolean isBedSpawn;
private final boolean isAnchorSpawn; private final boolean isAnchorSpawn;
private final boolean missingRespawnBlock;
private final RespawnReason respawnReason; private final RespawnReason respawnReason;
private final java.util.Set<RespawnFlag> respawnFlags; // Paper private final java.util.Set<RespawnFlag> respawnFlags;
@Deprecated(since = "1.16.1", forRemoval = true) @Deprecated(since = "1.16.1", forRemoval = true)
public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn) { public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn) {
@@ -33,23 +34,20 @@ public class PlayerRespawnEvent extends PlayerEvent {
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn, final boolean isAnchorSpawn, @NotNull final RespawnReason respawnReason) { public PlayerRespawnEvent(@NotNull final Player respawnPlayer, @NotNull final Location respawnLocation, final boolean isBedSpawn, final boolean isAnchorSpawn, @NotNull final RespawnReason respawnReason) {
// Paper start this(respawnPlayer, respawnLocation, isBedSpawn, isAnchorSpawn, false, respawnReason, com.google.common.collect.ImmutableSet.builder());
this(respawnPlayer, respawnLocation, isBedSpawn, isAnchorSpawn, respawnReason, com.google.common.collect.ImmutableSet.builder());
} }
@ApiStatus.Internal @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) {
// Paper end
super(respawnPlayer); super(respawnPlayer);
this.respawnLocation = respawnLocation; this.respawnLocation = respawnLocation;
this.isBedSpawn = isBedSpawn; this.isBedSpawn = isBedSpawn;
this.isAnchorSpawn = isAnchorSpawn; this.isAnchorSpawn = isAnchorSpawn;
this.respawnReason = respawnReason; this.respawnReason = respawnReason;
// Paper start this.missingRespawnBlock = missingRespawnBlock;
if (this.isBedSpawn) { respawnFlags.add(RespawnFlag.BED_SPAWN); } if (this.isBedSpawn) { respawnFlags.add(RespawnFlag.BED_SPAWN); }
if (this.isAnchorSpawn) { respawnFlags.add(RespawnFlag.ANCHOR_SPAWN); } if (this.isAnchorSpawn) { respawnFlags.add(RespawnFlag.ANCHOR_SPAWN); }
this.respawnFlags = respawnFlags.build(); this.respawnFlags = respawnFlags.build();
// Paper end
} }
/** /**
@@ -92,6 +90,19 @@ public class PlayerRespawnEvent extends PlayerEvent {
return isAnchorSpawn; return 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. * Gets the reason this respawn event was called.
* *
@@ -132,7 +143,6 @@ public class PlayerRespawnEvent extends PlayerEvent {
PLUGIN; PLUGIN;
} }
// Paper start
/** /**
* Get the set of flags that apply to this respawn. * Get the set of flags that apply to this respawn.
* *
@@ -157,5 +167,4 @@ public class PlayerRespawnEvent extends PlayerEvent {
*/ */
END_PORTAL, END_PORTAL,
} }
// Paper end
} }

View File

@@ -518,7 +518,7 @@
BlockPos respawnPosition = this.getRespawnPosition(); BlockPos respawnPosition = this.getRespawnPosition();
float respawnAngle = this.getRespawnAngle(); float respawnAngle = this.getRespawnAngle();
boolean isRespawnForced = this.isRespawnForced(); boolean isRespawnForced = this.isRespawnForced();
@@ -973,13 +_,66 @@ @@ -973,13 +_,67 @@
Optional<ServerPlayer.RespawnPosAngle> optional = findRespawnAndUseSpawnBlock(level, respawnPosition, respawnAngle, isRespawnForced, useCharge); Optional<ServerPlayer.RespawnPosAngle> optional = findRespawnAndUseSpawnBlock(level, respawnPosition, respawnAngle, isRespawnForced, useCharge);
if (optional.isPresent()) { if (optional.isPresent()) {
ServerPlayer.RespawnPosAngle respawnPosAngle = optional.get(); ServerPlayer.RespawnPosAngle respawnPosAngle = optional.get();
@@ -560,6 +560,7 @@
+ location, + location,
+ isBedSpawn, + isBedSpawn,
+ isAnchorSpawn, + isAnchorSpawn,
+ teleportTransition.missingRespawnBlock(),
+ respawnReason, + respawnReason,
+ builder + builder
+ ); + );

View File

@@ -36,3 +36,28 @@
return Math.max(fraction.divideBy(BundleContents.getWeight(stack)).intValue(), 0); return Math.max(fraction.divideBy(BundleContents.getWeight(stack)).intValue(), 0);
} }
@@ -206,15 +_,21 @@
}
public void toggleSelectedItem(int selectedItem) {
- this.selectedItem = this.selectedItem != selectedItem && selectedItem < this.items.size() ? selectedItem : -1;
- }
+ this.selectedItem = !indexIsOutsideAllowedBounds(selectedItem) ? selectedItem : -1; // Paper
+ }
+
+ // Paper start
+ private boolean indexIsOutsideAllowedBounds(int param0) {
+ return param0 < 0 || param0 >= this.items.size();
+ }
+ // Paper end
@Nullable
public ItemStack removeOne() {
if (this.items.isEmpty()) {
return null;
} else {
- int i = this.selectedItem != -1 && this.selectedItem < this.items.size() ? this.selectedItem : 0;
+ int i = !indexIsOutsideAllowedBounds(this.selectedItem) ? this.selectedItem : 0; // Paper
ItemStack itemStack = this.items.remove(i).copy();
this.weight = this.weight.subtract(BundleContents.getWeight(itemStack).multiplyBy(Fraction.getFraction(itemStack.getCount(), 1)));
this.toggleSelectedItem(-1);