SPIGOT-7759: Chunk not there when requested in ChunkUnloadEvent

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2024-06-15 16:47:43 +10:00
parent 9f79c6f74e
commit 7feadbf2ee
2 changed files with 19 additions and 8 deletions

View file

@ -52,6 +52,15 @@
this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair); this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
if (this.chunkAbsent(playerchunk, l)) { if (this.chunkAbsent(playerchunk, l)) {
GameProfilerFiller gameprofilerfiller = this.level.getProfiler(); GameProfilerFiller gameprofilerfiller = this.level.getProfiler();
@@ -237,7 +255,7 @@
}
private boolean chunkAbsent(@Nullable PlayerChunk playerchunk, int i) {
- return playerchunk == null || playerchunk.getTicketLevel() > i;
+ return playerchunk == null || playerchunk.oldTicketLevel > i; // CraftBukkit using oldTicketLevel for isLoaded checks
}
@Override
@@ -292,11 +310,31 @@ @@ -292,11 +310,31 @@
@Override @Override

View file

@ -24,13 +24,15 @@
this.levelHeightAccessor = levelheightaccessor; this.levelHeightAccessor = levelheightaccessor;
this.lightEngine = levellightengine; this.lightEngine = levellightengine;
this.onLevelChange = playerchunk_a; this.onLevelChange = playerchunk_a;
@@ -72,6 +76,16 @@ @@ -72,6 +76,18 @@
this.changedBlocksPerSection = new ShortSet[levelheightaccessor.getSectionsCount()]; this.changedBlocksPerSection = new ShortSet[levelheightaccessor.getSectionsCount()];
} }
+ // CraftBukkit start + // CraftBukkit start
+ public Chunk getFullChunkNow() { + public Chunk getFullChunkNow() {
+ return (Chunk) this.getChunkIfPresent(ChunkStatus.FULL); + // Note: We use the oldTicketLevel for isLoaded checks.
+ if (!ChunkLevel.fullStatus(this.oldTicketLevel).isOrAfter(FullChunkStatus.FULL)) return null;
+ return this.getFullChunkNowUnchecked();
+ } + }
+ +
+ public Chunk getFullChunkNowUnchecked() { + public Chunk getFullChunkNowUnchecked() {
@ -41,7 +43,7 @@
public CompletableFuture<ChunkResult<Chunk>> getTickingChunkFuture() { public CompletableFuture<ChunkResult<Chunk>> getTickingChunkFuture() {
return this.tickingChunkFuture; return this.tickingChunkFuture;
} }
@@ -86,7 +100,7 @@ @@ -86,7 +102,7 @@
@Nullable @Nullable
public Chunk getTickingChunk() { public Chunk getTickingChunk() {
@ -50,7 +52,7 @@
} }
@Nullable @Nullable
@@ -134,6 +148,7 @@ @@ -134,6 +150,7 @@
if (chunk != null) { if (chunk != null) {
int i = this.levelHeightAccessor.getSectionIndex(blockposition.getY()); int i = this.levelHeightAccessor.getSectionIndex(blockposition.getY());
@ -58,7 +60,7 @@
if (this.changedBlocksPerSection[i] == null) { if (this.changedBlocksPerSection[i] == null) {
this.hasChangedSections = true; this.hasChangedSections = true;
this.changedBlocksPerSection[i] = new ShortOpenHashSet(); this.changedBlocksPerSection[i] = new ShortOpenHashSet();
@@ -208,8 +223,11 @@ @@ -208,8 +225,11 @@
PacketPlayOutMultiBlockChange packetplayoutmultiblockchange = new PacketPlayOutMultiBlockChange(sectionposition, shortset, chunksection); PacketPlayOutMultiBlockChange packetplayoutmultiblockchange = new PacketPlayOutMultiBlockChange(sectionposition, shortset, chunksection);
this.broadcast(list, packetplayoutmultiblockchange); this.broadcast(list, packetplayoutmultiblockchange);
@ -71,7 +73,7 @@
}); });
} }
} }
@@ -275,7 +293,7 @@ @@ -275,7 +295,7 @@
this.pendingFullStateConfirmation = completablefuture1; this.pendingFullStateConfirmation = completablefuture1;
completablefuture.thenAccept((chunkresult) -> { completablefuture.thenAccept((chunkresult) -> {
chunkresult.ifSuccess((chunk) -> { chunkresult.ifSuccess((chunk) -> {
@ -80,7 +82,7 @@
}); });
}); });
} }
@@ -290,6 +308,30 @@ @@ -290,6 +310,30 @@
FullChunkStatus fullchunkstatus1 = ChunkLevel.fullStatus(this.ticketLevel); FullChunkStatus fullchunkstatus1 = ChunkLevel.fullStatus(this.ticketLevel);
boolean flag = fullchunkstatus.isOrAfter(FullChunkStatus.FULL); boolean flag = fullchunkstatus.isOrAfter(FullChunkStatus.FULL);
boolean flag1 = fullchunkstatus1.isOrAfter(FullChunkStatus.FULL); boolean flag1 = fullchunkstatus1.isOrAfter(FullChunkStatus.FULL);
@ -111,7 +113,7 @@
this.wasAccessibleSinceLastSave |= flag1; this.wasAccessibleSinceLastSave |= flag1;
if (!flag && flag1) { if (!flag && flag1) {
@@ -341,6 +383,26 @@ @@ -341,6 +385,26 @@
this.onLevelChange.onLevelChange(this.pos, this::getQueueLevel, this.ticketLevel, this::setQueueLevel); this.onLevelChange.onLevelChange(this.pos, this::getQueueLevel, this.ticketLevel, this::setQueueLevel);
this.oldTicketLevel = this.ticketLevel; this.oldTicketLevel = this.ticketLevel;