2019-04-23 04:00:00 +02:00
|
|
|
--- a/net/minecraft/server/PlayerChunk.java
|
|
|
|
+++ b/net/minecraft/server/PlayerChunk.java
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -42,7 +42,7 @@
|
2019-05-14 02:00:00 +02:00
|
|
|
this.fullChunkFuture = PlayerChunk.UNLOADED_CHUNK_FUTURE;
|
2019-04-23 04:00:00 +02:00
|
|
|
this.tickingFuture = PlayerChunk.UNLOADED_CHUNK_FUTURE;
|
|
|
|
this.entityTickingFuture = PlayerChunk.UNLOADED_CHUNK_FUTURE;
|
|
|
|
- this.chunkSave = CompletableFuture.completedFuture((Object) null);
|
|
|
|
+ this.chunkSave = CompletableFuture.completedFuture(null); // CraftBukkit - decompile error
|
|
|
|
this.dirtyBlocks = new short[64];
|
|
|
|
this.location = chunkcoordintpair;
|
|
|
|
this.lightEngine = lightengine;
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -54,6 +54,15 @@
|
2019-05-16 01:11:20 +02:00
|
|
|
this.a(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ public Chunk getFullChunk() {
|
2019-06-12 20:05:29 +02:00
|
|
|
+ if (!getChunkState(this.oldTicketLevel).isAtLeast(PlayerChunk.State.BORDER)) return null; // note: using oldTicketLevel for isLoaded checks
|
2019-05-27 22:30:00 +02:00
|
|
|
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> statusFuture = this.getStatusFutureUnchecked(ChunkStatus.FULL);
|
2019-05-16 01:11:20 +02:00
|
|
|
+ Either<IChunkAccess, PlayerChunk.Failure> either = (Either<IChunkAccess, PlayerChunk.Failure>) statusFuture.getNow(null);
|
|
|
|
+ return either == null ? null : (Chunk) either.left().orElse(null);
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
|
|
|
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> getStatusFutureUnchecked(ChunkStatus chunkstatus) {
|
|
|
|
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = (CompletableFuture) this.statusFutures.get(chunkstatus.c());
|
|
|
|
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -79,9 +88,9 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
@Nullable
|
|
|
|
public Chunk getChunk() {
|
|
|
|
CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture = this.a();
|
|
|
|
- Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow((Object) null);
|
|
|
|
+ Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error
|
|
|
|
|
|
|
|
- return either == null ? null : (Chunk) either.left().orElse((Object) null);
|
|
|
|
+ return either == null ? null : (Chunk) either.left().orElse(null); // CraftBukkit - decompile error
|
|
|
|
}
|
|
|
|
|
2019-07-20 01:00:00 +02:00
|
|
|
@Nullable
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -210,7 +219,7 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = (CompletableFuture) this.statusFutures.get(i);
|
|
|
|
|
|
|
|
if (completablefuture != null) {
|
|
|
|
- Either<IChunkAccess, PlayerChunk.Failure> either = (Either) completablefuture.getNow((Object) null);
|
|
|
|
+ Either<IChunkAccess, PlayerChunk.Failure> either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error
|
|
|
|
|
|
|
|
if (either == null || either.left().isPresent()) {
|
|
|
|
return completablefuture;
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -265,6 +274,30 @@
|
2019-05-16 01:11:20 +02:00
|
|
|
boolean flag1 = this.ticketLevel <= PlayerChunkMap.GOLDEN_TICKET;
|
2019-05-27 22:30:00 +02:00
|
|
|
PlayerChunk.State playerchunk_state = getChunkState(this.oldTicketLevel);
|
|
|
|
PlayerChunk.State playerchunk_state1 = getChunkState(this.ticketLevel);
|
2019-05-16 01:11:20 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ // ChunkUnloadEvent: Called before the chunk is unloaded: isChunkLoaded is still true and chunk can still be modified by plugins.
|
2019-05-27 22:30:00 +02:00
|
|
|
+ if (playerchunk_state.isAtLeast(PlayerChunk.State.BORDER) && !playerchunk_state1.isAtLeast(PlayerChunk.State.BORDER)) {
|
2020-03-03 02:19:06 +01:00
|
|
|
+ this.getStatusFutureUnchecked(ChunkStatus.FULL).thenAccept((either) -> {
|
|
|
|
+ Chunk chunk = (Chunk)either.left().orElse(null);
|
|
|
|
+ if (chunk != null) {
|
|
|
|
+ playerchunkmap.callbackExecutor.execute(() -> {
|
|
|
|
+ // Minecraft will apply the chunks tick lists to the world once the chunk got loaded, and then store the tick
|
|
|
|
+ // lists again inside the chunk once the chunk becomes inaccessible and set the chunk's needsSaving flag.
|
|
|
|
+ // These actions may however happen deferred, so we manually set the needsSaving flag already here.
|
|
|
|
+ chunk.setNeedsSaving(true);
|
|
|
|
+ chunk.unloadCallback();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }).exceptionally((throwable) -> {
|
|
|
|
+ // ensure exceptions are printed, by default this is not the case
|
|
|
|
+ MinecraftServer.LOGGER.fatal("Failed to schedule unload callback for chunk " + PlayerChunk.this.location, throwable);
|
|
|
|
+ return null;
|
|
|
|
+ });
|
2019-07-13 20:19:44 +02:00
|
|
|
+
|
|
|
|
+ // Run callback right away if the future was already done
|
|
|
|
+ playerchunkmap.callbackExecutor.run();
|
2019-05-16 01:11:20 +02:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2019-05-27 22:30:00 +02:00
|
|
|
CompletableFuture completablefuture;
|
2019-05-16 01:11:20 +02:00
|
|
|
|
2019-05-27 22:30:00 +02:00
|
|
|
if (flag) {
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -296,7 +329,7 @@
|
2019-05-14 02:00:00 +02:00
|
|
|
if (flag2 && !flag3) {
|
|
|
|
completablefuture = this.fullChunkFuture;
|
|
|
|
this.fullChunkFuture = PlayerChunk.UNLOADED_CHUNK_FUTURE;
|
|
|
|
- this.a(completablefuture.thenApply((either1) -> {
|
|
|
|
+ this.a(((CompletableFuture<Either<Chunk, PlayerChunk.Failure>>) completablefuture).thenApply((either1) -> { // CraftBukkit - decompile error
|
|
|
|
playerchunkmap.getClass();
|
|
|
|
return either1.ifLeft(playerchunkmap::a);
|
|
|
|
}));
|
2020-06-25 02:00:00 +02:00
|
|
|
@@ -334,6 +367,26 @@
|
2019-05-16 01:11:20 +02:00
|
|
|
|
2020-06-25 02:00:00 +02:00
|
|
|
this.v.a(this.location, this::k, this.ticketLevel, this::d);
|
2019-05-16 01:11:20 +02:00
|
|
|
this.oldTicketLevel = this.ticketLevel;
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ // ChunkLoadEvent: Called after the chunk is loaded: isChunkLoaded returns true and chunk is ready to be modified by plugins.
|
2019-05-27 22:30:00 +02:00
|
|
|
+ if (!playerchunk_state.isAtLeast(PlayerChunk.State.BORDER) && playerchunk_state1.isAtLeast(PlayerChunk.State.BORDER)) {
|
2020-03-03 02:19:06 +01:00
|
|
|
+ this.getStatusFutureUnchecked(ChunkStatus.FULL).thenAccept((either) -> {
|
|
|
|
+ Chunk chunk = (Chunk)either.left().orElse(null);
|
|
|
|
+ if (chunk != null) {
|
|
|
|
+ playerchunkmap.callbackExecutor.execute(() -> {
|
|
|
|
+ chunk.loadCallback();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }).exceptionally((throwable) -> {
|
|
|
|
+ // ensure exceptions are printed, by default this is not the case
|
|
|
|
+ MinecraftServer.LOGGER.fatal("Failed to schedule load callback for chunk " + PlayerChunk.this.location, throwable);
|
|
|
|
+ return null;
|
|
|
|
+ });
|
2019-07-13 20:19:44 +02:00
|
|
|
+
|
|
|
|
+ // Run callback right away if the future was already done
|
|
|
|
+ playerchunkmap.callbackExecutor.run();
|
2019-05-16 01:11:20 +02:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2019-05-27 22:30:00 +02:00
|
|
|
public static ChunkStatus getChunkStatus(int i) {
|