Fix NPE while trying to respawn an already disconnected player (#11353)

This commit is contained in:
Pedro 2024-09-07 15:34:03 -04:00 committed by GitHub
parent 21f125f3c2
commit 0e825274e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 27 additions and 20 deletions

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Add PlayerPostRespawnEvent
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 79203d0e5cdb86d9e2fb22cdaeb8cf3a93e43dcc..a2a913e20cdea9518da5ad0d1ef8908538860890 100644
index 79203d0e5cdb86d9e2fb22cdaeb8cf3a93e43dcc..8cd80ea83ddcfd5052c8d8c19d3edb42538d1e15 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -738,6 +738,10 @@ public abstract class PlayerList {
@ -19,18 +19,25 @@ index 79203d0e5cdb86d9e2fb22cdaeb8cf3a93e43dcc..a2a913e20cdea9518da5ad0d1ef89085
// CraftBukkit start - fire PlayerRespawnEvent
DimensionTransition dimensiontransition;
@@ -745,6 +749,10 @@ public abstract class PlayerList {
@@ -745,11 +749,16 @@ public abstract class PlayerList {
dimensiontransition = entityplayer.findRespawnPositionAndUseSpawnBlock(flag, DimensionTransition.DO_NOTHING, reason);
if (!flag) entityplayer.reset(); // SPIGOT-4785
+ // Paper start - Add PlayerPostRespawnEvent
+ if (dimensiontransition == null) return entityplayer; // Early exit, mirrors belows early return for disconnected players in respawn event
+ isRespawn = true;
+ location = CraftLocation.toBukkit(dimensiontransition.pos(), dimensiontransition.newLevel().getWorld(), dimensiontransition.yRot(), dimensiontransition.xRot());
+ // Paper end - Add PlayerPostRespawnEvent
} else {
dimensiontransition = new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3.ZERO, location.getYaw(), location.getPitch(), DimensionTransition.DO_NOTHING);
}
@@ -795,6 +803,11 @@ public abstract class PlayerList {
// Spigot Start
- if (dimensiontransition == null) {
+ if (dimensiontransition == null) { // Paper - Add PlayerPostRespawnEvent - diff on change - spigot early returns if respawn pos is null, that is how they handle disconnected player in respawn event
return entityplayer;
}
// Spigot End
@@ -795,6 +804,11 @@ public abstract class PlayerList {
if (iblockdata.is(Blocks.RESPAWN_ANCHOR)) {
entityplayer1.connection.send(new ClientboundSoundPacket(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 1.0F, 1.0F, worldserver.getRandom().nextLong()));
}
@ -42,7 +49,7 @@ index 79203d0e5cdb86d9e2fb22cdaeb8cf3a93e43dcc..a2a913e20cdea9518da5ad0d1ef89085
}
// Added from changeDimension
this.sendAllPlayerInfo(entityplayer); // Update health, etc...
@@ -816,6 +829,13 @@ public abstract class PlayerList {
@@ -816,6 +830,13 @@ public abstract class PlayerList {
if (entityplayer.connection.isDisconnected()) {
this.save(entityplayer);
}