Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
This commit is contained in:
parent
de6173b061
commit
8c5b837e05
720 changed files with 978 additions and 1034 deletions
|
@ -8,10 +8,10 @@ Adds API's to load or generate chunks asynchronously.
|
|||
Also adds utility methods to Entity to teleport asynchronously.
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||
index ba9ab1d46effe1e6c08cebddb8b856e2b294d7cb..c77ca55c0686512e6d50b559139b6d6bbeb61062 100644
|
||||
index ba9ab1d46effe1e6c08cebddb8b856e2b294d7cb..f314f8bc5c437c5703c1e093278d9046903ff2c8 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -977,6 +977,472 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -977,6 +977,509 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
}
|
||||
// Paper end - additional getNearbyEntities API
|
||||
|
||||
|
@ -63,10 +63,7 @@ index ba9ab1d46effe1e6c08cebddb8b856e2b294d7cb..c77ca55c0686512e6d50b559139b6d6b
|
|||
+ */
|
||||
+ @Deprecated(since = "1.13.1")
|
||||
+ public default void getChunkAtAsync(int x, int z, @NotNull ChunkLoadCallback cb) {
|
||||
+ getChunkAtAsync(x, z, true).thenAccept(cb::onLoad).exceptionally((ex) -> {
|
||||
+ Bukkit.getLogger().log(java.util.logging.Level.WARNING, "Exception in chunk load callback", ex);
|
||||
+ return null;
|
||||
+ });
|
||||
+ this.getChunkAtAsync(x, z, (java.util.function.Consumer<Chunk>)cb);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -89,10 +86,7 @@ index ba9ab1d46effe1e6c08cebddb8b856e2b294d7cb..c77ca55c0686512e6d50b559139b6d6b
|
|||
+ */
|
||||
+ @Deprecated(since = "1.13.1")
|
||||
+ public default void getChunkAtAsync(@NotNull Location loc, @NotNull ChunkLoadCallback cb) {
|
||||
+ getChunkAtAsync(loc, true).thenAccept(cb::onLoad).exceptionally((ex) -> {
|
||||
+ Bukkit.getLogger().log(java.util.logging.Level.WARNING, "Exception in chunk load callback", ex);
|
||||
+ return null;
|
||||
+ });
|
||||
+ this.getChunkAtAsync(loc.getBlockX() >> 4, loc.getBlockZ() >> 4, cb);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -115,10 +109,7 @@ index ba9ab1d46effe1e6c08cebddb8b856e2b294d7cb..c77ca55c0686512e6d50b559139b6d6b
|
|||
+ */
|
||||
+ @Deprecated(since = "1.13.1")
|
||||
+ public default void getChunkAtAsync(@NotNull Block block, @NotNull ChunkLoadCallback cb) {
|
||||
+ getChunkAtAsync(block, true).thenAccept(cb::onLoad).exceptionally((ex) -> {
|
||||
+ Bukkit.getLogger().log(java.util.logging.Level.WARNING, "Exception in chunk load callback", ex);
|
||||
+ return null;
|
||||
+ });
|
||||
+ this.getChunkAtAsync(block.getX() >> 4, block.getZ() >> 4, cb);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -140,10 +131,7 @@ index ba9ab1d46effe1e6c08cebddb8b856e2b294d7cb..c77ca55c0686512e6d50b559139b6d6b
|
|||
+ * will be executed synchronously
|
||||
+ */
|
||||
+ default void getChunkAtAsync(final int x, final int z, final @NotNull Consumer<? super Chunk> cb) {
|
||||
+ this.getChunkAtAsync(x, z, true).thenAccept(cb).exceptionally((ex) -> {
|
||||
+ Bukkit.getLogger().log(java.util.logging.Level.WARNING, "Exception in chunk load callback", ex);
|
||||
+ return null;
|
||||
+ });
|
||||
+ this.getChunkAtAsync(x, z, true, cb);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -166,13 +154,58 @@ index ba9ab1d46effe1e6c08cebddb8b856e2b294d7cb..c77ca55c0686512e6d50b559139b6d6b
|
|||
+ * will be executed synchronously
|
||||
+ */
|
||||
+ default void getChunkAtAsync(final int x, final int z, final boolean gen, final @NotNull Consumer<? super Chunk> cb) {
|
||||
+ this.getChunkAtAsync(x, z, gen).thenAccept(cb).exceptionally((ex) -> {
|
||||
+ Bukkit.getLogger().log(java.util.logging.Level.WARNING, "Exception in chunk load callback", ex);
|
||||
+ return null;
|
||||
+ });
|
||||
+ this.getChunkAtAsync(x, z, gen, false, cb);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Requests a {@link Chunk} to be loaded at the given coordinates
|
||||
+ *
|
||||
+ * This method makes no guarantee on how fast the chunk will load,
|
||||
+ * and will return the chunk to the callback at a later time.
|
||||
+ *
|
||||
+ * You should use this method if you need a chunk but do not need it
|
||||
+ * immediately, and you wish to let the server control the speed
|
||||
+ * of chunk loads, keeping performance in mind.
|
||||
+ *
|
||||
+ * The {@link java.util.function.Consumer} will always be executed synchronously
|
||||
+ * on the main Server Thread.
|
||||
+ *
|
||||
+ * @param x Chunk X-coordinate of the chunk - floor(world coordinate / 16)
|
||||
+ * @param z Chunk Z-coordinate of the chunk - floor(world coordinate / 16)
|
||||
+ * @param gen Should we generate a chunk if it doesn't exist or not
|
||||
+ * @param urgent If true, the chunk may be prioritised to be loaded above other chunks in queue
|
||||
+ * @param cb Callback to receive the chunk when it is loaded.
|
||||
+ * will be executed synchronously
|
||||
+ */
|
||||
+ void getChunkAtAsync(final int x, final int z, final boolean gen, final boolean urgent, final @NotNull Consumer<? super Chunk> cb);
|
||||
+
|
||||
+ /**
|
||||
+ * Requests all chunks with x between [minX, maxZ] and z
|
||||
+ * between [minZ, maxZ] to be loaded.
|
||||
+ *
|
||||
+ * This method makes no guarantee on how fast the chunk will load,
|
||||
+ * and will invoke the callback at possibly a later time.
|
||||
+ *
|
||||
+ * You should use this method if you need chunks loaded but do not need them
|
||||
+ * immediately, and you wish to let the server control the speed
|
||||
+ * of chunk loads, keeping performance in mind.
|
||||
+ *
|
||||
+ * The {@link Runnable} will always be executed synchronously
|
||||
+ * on the main Server Thread, and when invoked all chunks requested will be loaded.
|
||||
+ *
|
||||
+ * @param minX Minimum chunk X-coordinate of the chunk - floor(world coordinate / 16)
|
||||
+ * @param minZ Minimum chunk Z-coordinate of the chunk - floor(world coordinate / 16)
|
||||
+ * @param maxX Maximum chunk X-coordinate of the chunk - floor(world coordinate / 16)
|
||||
+ * @param maxZ Maximum chunk Z-coordinate of the chunk - floor(world coordinate / 16)
|
||||
+ * @param urgent If true, the chunks may be prioritised to be loaded above other chunks in queue
|
||||
+ * @param cb Callback to invoke when all chunks are loaded.
|
||||
+ * Will be executed synchronously
|
||||
+ * @see Chunk
|
||||
+ */
|
||||
+ void getChunksAtAsync(final int minX, final int minZ, final int maxX, final int maxZ, final boolean urgent,
|
||||
+ final Runnable cb);
|
||||
+
|
||||
+ /**
|
||||
+ * Requests a {@link Chunk} to be loaded at the given {@link Location}
|
||||
+ *
|
||||
+ * This method makes no guarantee on how fast the chunk will load,
|
||||
|
@ -478,7 +511,11 @@ index ba9ab1d46effe1e6c08cebddb8b856e2b294d7cb..c77ca55c0686512e6d50b559139b6d6b
|
|||
+ return this.getChunkAtAsync(x, z, true, true);
|
||||
+ }
|
||||
+
|
||||
+ java.util.concurrent.@NotNull CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen, boolean urgent);
|
||||
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen, boolean urgent) {
|
||||
+ java.util.concurrent.CompletableFuture<Chunk> ret = new java.util.concurrent.CompletableFuture<>();
|
||||
+ this.getChunkAtAsync(x, z, gen, urgent, ret::complete);
|
||||
+ return ret;
|
||||
+ }
|
||||
+ // Paper end - async chunks API
|
||||
+
|
||||
/**
|
||||
|
|
|
@ -5,10 +5,10 @@ Subject: [PATCH] Add sun related API
|
|||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||
index c77ca55c0686512e6d50b559139b6d6bbeb61062..7dbc2e4883feb5b0b1a20cf36cda01ef3795a262 100644
|
||||
index f314f8bc5c437c5703c1e093278d9046903ff2c8..a8fe8c2f4327f0bee60eeac565620117f3fde2ee 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -1798,6 +1798,16 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -1835,6 +1835,16 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
*/
|
||||
public void setFullTime(long time);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ that continues to have use (internally).
|
|||
These do not help plugin developers if they bring moise noise than value.
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
||||
index 577b4b89b50441572f0edd9325047c38e25e782e..949ffc320502e46493183cc3ef621d9c4edbe7d6 100644
|
||||
index f9067281bd5f1ac11dcb9cc2e19f3c5f17face21..03e836b9c2e6d141396cfe4a0034c5dcdcaf9e90 100644
|
||||
--- a/src/main/java/org/bukkit/Bukkit.java
|
||||
+++ b/src/main/java/org/bukkit/Bukkit.java
|
||||
@@ -883,9 +883,8 @@ public final class Bukkit {
|
||||
|
@ -470,7 +470,7 @@ index 6277451c3c6c551078c237cd767b6d70c4f585ea..7d33b3e2f81c14d3aeb800b39e782383
|
|||
CRACKED(0x0),
|
||||
GLYPHED(0x1),
|
||||
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||||
index 08f6f85388e4c3e3aae40f709109f8706a400675..c6ebdefe940e5e3ab04aac0f22924ef5d876d328 100644
|
||||
index 2719461e49a74f979d49dea9c664dfe3da8d2c8e..44ebe899f4278b8f7422385710bdc180375475fd 100644
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -744,9 +744,8 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||||
|
@ -590,7 +590,7 @@ index e455eb21abf121dc6ff10ff8a13dd06f67096a8f..bbc01e7c192ae6689c301670047ff114
|
|||
return origin;
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||
index 7dbc2e4883feb5b0b1a20cf36cda01ef3795a262..e4471e86e1b0993425087d8331e7c3d9896b3908 100644
|
||||
index a8fe8c2f4327f0bee60eeac565620117f3fde2ee..7ef12976430272d814374ee066e975457111b7f3 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -418,9 +418,8 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
|
@ -604,7 +604,7 @@ index 7dbc2e4883feb5b0b1a20cf36cda01ef3795a262..e4471e86e1b0993425087d8331e7c3d9
|
|||
public boolean refreshChunk(int x, int z);
|
||||
|
||||
/**
|
||||
@@ -3813,6 +3812,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -3850,6 +3849,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
StructureSearchResult locateNearestStructure(@NotNull Location origin, @NotNull Structure structure, int radius, boolean findUnexplored);
|
||||
|
||||
// Spigot start
|
||||
|
@ -612,7 +612,7 @@ index 7dbc2e4883feb5b0b1a20cf36cda01ef3795a262..e4471e86e1b0993425087d8331e7c3d9
|
|||
public class Spigot {
|
||||
|
||||
/**
|
||||
@@ -3846,7 +3846,11 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -3883,7 +3883,11 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -624,7 +624,7 @@ index 7dbc2e4883feb5b0b1a20cf36cda01ef3795a262..e4471e86e1b0993425087d8331e7c3d9
|
|||
Spigot spigot();
|
||||
// Spigot end
|
||||
|
||||
@@ -4064,9 +4068,9 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -4101,9 +4105,9 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
* Gets the dimension ID of this environment
|
||||
*
|
||||
* @return dimension ID
|
||||
|
@ -636,7 +636,7 @@ index 7dbc2e4883feb5b0b1a20cf36cda01ef3795a262..e4471e86e1b0993425087d8331e7c3d9
|
|||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -4076,9 +4080,9 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -4113,9 +4117,9 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
*
|
||||
* @param id The ID of the environment
|
||||
* @return The environment
|
||||
|
|
|
@ -5,10 +5,10 @@ Subject: [PATCH] More World API
|
|||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||
index e4471e86e1b0993425087d8331e7c3d9896b3908..ce1f3ffbab6a8dc8395e3a5b74a7874bb6b38aa9 100644
|
||||
index 7ef12976430272d814374ee066e975457111b7f3..b22530070b95667e2b548ef1e68e536a5b8ee138 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -3811,6 +3811,72 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -3848,6 +3848,72 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@Nullable
|
||||
StructureSearchResult locateNearestStructure(@NotNull Location origin, @NotNull Structure structure, int radius, boolean findUnexplored);
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@ Subject: [PATCH] Expand FallingBlock API
|
|||
Co-authored-by: Lukas Planz <lukas.planz@web.de>
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||
index 2720f290a632dd32fd9e70a40e73db9d1d161e94..f037f46a9c6ce894f24af14c20fb514a58a8aee9 100644
|
||||
index 2da3b4d3aa7bedd7c9e253d4036cef1f0d911d45..24eaf74420f6fbd4f0a0f13b719f57b50696aef3 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -2244,8 +2244,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -2281,8 +2281,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
* @return The spawned {@link FallingBlock} instance
|
||||
* @throws IllegalArgumentException if {@link Location} or {@link
|
||||
* MaterialData} are null or {@link Material} of the {@link MaterialData} is not a block
|
||||
|
@ -24,7 +24,7 @@ index 2720f290a632dd32fd9e70a40e73db9d1d161e94..f037f46a9c6ce894f24af14c20fb514a
|
|||
public FallingBlock spawnFallingBlock(@NotNull Location location, @NotNull MaterialData data) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
@@ -2258,8 +2260,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -2295,8 +2297,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
* @return The spawned {@link FallingBlock} instance
|
||||
* @throws IllegalArgumentException if {@link Location} or {@link
|
||||
* BlockData} are null
|
||||
|
@ -35,7 +35,7 @@ index 2720f290a632dd32fd9e70a40e73db9d1d161e94..f037f46a9c6ce894f24af14c20fb514a
|
|||
public FallingBlock spawnFallingBlock(@NotNull Location location, @NotNull BlockData data) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
@@ -2276,7 +2280,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -2313,7 +2317,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
* @return The spawned {@link FallingBlock} instance
|
||||
* @throws IllegalArgumentException if {@link Location} or {@link
|
||||
* Material} are null or {@link Material} is not a block
|
||||
|
|
|
@ -5,10 +5,10 @@ Subject: [PATCH] Add predicate for blocks when raytracing
|
|||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||
index f037f46a9c6ce894f24af14c20fb514a58a8aee9..86fd5f3d322b6203f02ca7c427ccd56336b93fc0 100644
|
||||
index 24eaf74420f6fbd4f0a0f13b719f57b50696aef3..9a473448427b48038e097796459ff0352f5a54cc 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -1649,6 +1649,27 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -1686,6 +1686,27 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@Nullable
|
||||
public RayTraceResult rayTraceEntities(@NotNull Location start, @NotNull Vector direction, double maxDistance, double raySize, @Nullable Predicate<? super Entity> filter);
|
||||
|
||||
|
@ -36,7 +36,7 @@ index f037f46a9c6ce894f24af14c20fb514a58a8aee9..86fd5f3d322b6203f02ca7c427ccd563
|
|||
/**
|
||||
* Performs a ray trace that checks for block collisions using the blocks'
|
||||
* precise collision shapes.
|
||||
@@ -1712,6 +1733,34 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -1749,6 +1770,34 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@Nullable
|
||||
public RayTraceResult rayTraceBlocks(@NotNull Location start, @NotNull Vector direction, double maxDistance, @NotNull FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks);
|
||||
|
||||
|
@ -71,7 +71,7 @@ index f037f46a9c6ce894f24af14c20fb514a58a8aee9..86fd5f3d322b6203f02ca7c427ccd563
|
|||
/**
|
||||
* Performs a ray trace that checks for both block and entity collisions.
|
||||
* <p>
|
||||
@@ -1745,6 +1794,42 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -1782,6 +1831,42 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@Nullable
|
||||
public RayTraceResult rayTrace(@NotNull Location start, @NotNull Vector direction, double maxDistance, @NotNull FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks, double raySize, @Nullable Predicate<? super Entity> filter);
|
||||
|
||||
|
|
|
@ -39,10 +39,10 @@ index 983a8c20a06d2b509602b27f49c090598b8ecc42..fa98599e3eee37bf68f0e9813497c718
|
|||
+ // Paper end
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||
index 16570c3c7ed5e7ad25f20c1034f7b966d6e694da..adcd8161846b06fd1a7895750f98b629204a8406 100644
|
||||
index ba57efc267e78d28c67648b0e994ffca3b8a8823..bb70a797ea5f0db5bd9f2397944687530b0d1cf3 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -4127,6 +4127,17 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@@ -4164,6 +4164,17 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||
@Nullable
|
||||
public Raid locateNearestRaid(@NotNull Location location, int radius);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue