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 450a3cc543..441902ee28 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 @@ -18,8 +18,9 @@ public class PlayerRespawnEvent extends PlayerEvent { private Location respawnLocation; private final boolean isBedSpawn; private final boolean isAnchorSpawn; + private final boolean missingRespawnBlock; private final RespawnReason respawnReason; - private final java.util.Set respawnFlags; // Paper + private final java.util.Set respawnFlags; @Deprecated(since = "1.16.1", forRemoval = true) 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) 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, 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 respawnFlags) { - // Paper end + 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 respawnFlags) { super(respawnPlayer); this.respawnLocation = respawnLocation; this.isBedSpawn = isBedSpawn; this.isAnchorSpawn = isAnchorSpawn; this.respawnReason = respawnReason; - // Paper start + this.missingRespawnBlock = missingRespawnBlock; if (this.isBedSpawn) { respawnFlags.add(RespawnFlag.BED_SPAWN); } if (this.isAnchorSpawn) { respawnFlags.add(RespawnFlag.ANCHOR_SPAWN); } this.respawnFlags = respawnFlags.build(); - // Paper end } /** @@ -92,6 +90,19 @@ public class PlayerRespawnEvent extends PlayerEvent { return isAnchorSpawn; } + /** + * Gets whether the player is missing a valid respawn block. + *

+ * 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. * @@ -132,7 +143,6 @@ public class PlayerRespawnEvent extends PlayerEvent { PLUGIN; } - // Paper start /** * Get the set of flags that apply to this respawn. * @@ -157,5 +167,4 @@ public class PlayerRespawnEvent extends PlayerEvent { */ END_PORTAL, } - // Paper end } diff --git a/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch b/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch index a1ac8281e2..5e8d6deaf1 100644 --- a/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch @@ -518,7 +518,7 @@ BlockPos respawnPosition = this.getRespawnPosition(); float respawnAngle = this.getRespawnAngle(); boolean isRespawnForced = this.isRespawnForced(); -@@ -973,13 +_,66 @@ +@@ -973,13 +_,67 @@ Optional optional = findRespawnAndUseSpawnBlock(level, respawnPosition, respawnAngle, isRespawnForced, useCharge); if (optional.isPresent()) { ServerPlayer.RespawnPosAngle respawnPosAngle = optional.get(); @@ -560,6 +560,7 @@ + location, + isBedSpawn, + isAnchorSpawn, ++ teleportTransition.missingRespawnBlock(), + respawnReason, + builder + ); diff --git a/paper-server/patches/sources/net/minecraft/world/item/component/BundleContents.java.patch b/paper-server/patches/sources/net/minecraft/world/item/component/BundleContents.java.patch index c5caf800fc..97b880bd11 100644 --- a/paper-server/patches/sources/net/minecraft/world/item/component/BundleContents.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/item/component/BundleContents.java.patch @@ -36,3 +36,28 @@ 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);