From 8b2a437b9e0e993b3d85aa55f5e9866759e79008 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 23 May 2020 18:38:29 -0400 Subject: [PATCH] Fix plugins calling getChunkAtAsync asynchronously While this method has async in it's name, it's not actually meant to be called asynchronously.... It just means IT will load the chunk asynchronously without blocking main. So fix this so that if a plugin calls it async, it forces the request back to main thread. --- .../0390-Asynchronous-chunk-IO-and-loading.patch | 16 ++++++++++++++-- ...05-No-Tick-view-distance-implementation.patch | 4 ++-- ...hunk-Priority-Urgency-System-for-Chunks.patch | 6 +++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Spigot-Server-Patches/0390-Asynchronous-chunk-IO-and-loading.patch b/Spigot-Server-Patches/0390-Asynchronous-chunk-IO-and-loading.patch index fc427562fd..a5fe97b5ea 100644 --- a/Spigot-Server-Patches/0390-Asynchronous-chunk-IO-and-loading.patch +++ b/Spigot-Server-Patches/0390-Asynchronous-chunk-IO-and-loading.patch @@ -4127,7 +4127,7 @@ index 58018bfcee5396d440b0f022a7aa9ed452e67ec5..f84248ad9f90aaaf02afa35a4147fb11 } public void removeTicketsForSpawn(int radiusInBlocks, BlockPosition spawn) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index 50467656df0b54c2dcba8696b5677a2fc975b178..711bb5c5f4a37357007e8c6441b61c474952ba4d 100644 +index 50467656df0b54c2dcba8696b5677a2fc975b178..1c5154f8f1b02d8e84fc54afeacb56a86e244ec3 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -75,6 +75,7 @@ import net.minecraft.server.GroupDataEntity; @@ -4170,7 +4170,7 @@ index 50467656df0b54c2dcba8696b5677a2fc975b178..711bb5c5f4a37357007e8c6441b61c47 // fall through to load // we do this so we do not re-read the chunk data on disk -@@ -2443,6 +2445,22 @@ public class CraftWorld implements World { +@@ -2443,6 +2445,34 @@ public class CraftWorld implements World { return new CraftDragonBattle(((WorldProviderTheEnd) worldProvider).o()); // PAIL rename getDragonBattle } @@ -4182,6 +4182,18 @@ index 50467656df0b54c2dcba8696b5677a2fc975b178..711bb5c5f4a37357007e8c6441b61c47 + if (immediate != null) { + return CompletableFuture.completedFuture(immediate.getBukkitChunk()); + } ++ } else { ++ CompletableFuture future = new CompletableFuture(); ++ world.getMinecraftServer().execute(() -> { ++ getChunkAtAsync(x, z, gen, urgent).whenComplete((chunk, err) -> { ++ if (err != null) { ++ future.completeExceptionally(err); ++ } else { ++ future.complete(chunk); ++ } ++ }); ++ }); ++ return future; + } + + return this.world.getChunkProvider().getChunkAtAsynchronously(x, z, gen, urgent).thenComposeAsync((either) -> { diff --git a/Spigot-Server-Patches/0505-No-Tick-view-distance-implementation.patch b/Spigot-Server-Patches/0505-No-Tick-view-distance-implementation.patch index 346602167d..cb9207ae60 100644 --- a/Spigot-Server-Patches/0505-No-Tick-view-distance-implementation.patch +++ b/Spigot-Server-Patches/0505-No-Tick-view-distance-implementation.patch @@ -589,10 +589,10 @@ index 899c535c4056cd2375ab8f834f03267d405f4bda..0e6368d0fb3beccb492ae3867fb4e228 if (!this.isClientSide && (i & 1) != 0) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index b184f8ed8ce86965c3ef9aef179126a4d69275e8..bbfbfeed12890c9d20d78a9661ab172c901f008c 100644 +index c77c59223eb652346502b9a896e0ad536395e444..5f180bb77b736220c848357b2cac4d0d2b99e3df 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -@@ -2482,10 +2482,39 @@ public class CraftWorld implements World { +@@ -2494,10 +2494,39 @@ public class CraftWorld implements World { // Spigot start @Override public int getViewDistance() { diff --git a/Spigot-Server-Patches/0529-Implement-Chunk-Priority-Urgency-System-for-Chunks.patch b/Spigot-Server-Patches/0529-Implement-Chunk-Priority-Urgency-System-for-Chunks.patch index 470bcee2a1..fad222366e 100644 --- a/Spigot-Server-Patches/0529-Implement-Chunk-Priority-Urgency-System-for-Chunks.patch +++ b/Spigot-Server-Patches/0529-Implement-Chunk-Priority-Urgency-System-for-Chunks.patch @@ -819,11 +819,11 @@ index 8055f5998213ab1c6c10d03d88d2b14d220a5e40..24ec5d77ca7fdf12585c1bb744255438 public static TicketType a(String s, Comparator comparator) { return new TicketType<>(s, comparator, 0L); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index bbfbfeed12890c9d20d78a9661ab172c901f008c..7230ddbf6eb765390543bdb3ff8c08d383bb2666 100644 +index 5f180bb77b736220c848357b2cac4d0d2b99e3df..d3c5b7d1904a6cbd65db406639ed2ba90ec9fd2a 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -@@ -2472,6 +2472,10 @@ public class CraftWorld implements World { - } +@@ -2484,6 +2484,10 @@ public class CraftWorld implements World { + return future; } + if (!urgent) {