Add Urgent API for Async Chunks API and use it for Async Teleport
This also cleans up the implementation of Async Chunks to get rid of most Consumer callbacks and instead return futures. This lets us propogate errors correctly up the future chain (barring one isn't lost even deeper in the chain...) So exceptions can now bubble to plugins using getChunkAtAsync
This commit is contained in:
parent
ad8e59dc79
commit
e5f6489602
20 changed files with 308 additions and 147 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 e5b76d59fdcc85344cf3932b38ab096155d2eec3..62aa9bd67cf652cc9fcd4ef2ced3bc48e120763d 100644
|
||||
index e5b76d59fdcc85344cf3932b38ab096155d2eec3..8fe496ad8f566183e2280582d00c3b7751f06d75 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -221,6 +221,358 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@@ -221,6 +221,467 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
public default Chunk getChunkAt(long chunkKey) {
|
||||
return getChunkAt((int) chunkKey, (int) (chunkKey >> 32));
|
||||
}
|
||||
|
@ -366,15 +366,124 @@ index e5b76d59fdcc85344cf3932b38ab096155d2eec3..62aa9bd67cf652cc9fcd4ef2ced3bc48
|
|||
+ * @return Future that will resolve when the chunk is loaded
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen);
|
||||
+ public default java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen) {
|
||||
+ return getChunkAtAsync(x, z, gen, false);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * 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 future will always be executed synchronously
|
||||
+ * on the main Server Thread.
|
||||
+ * @param loc Location to load the corresponding chunk from
|
||||
+ * @return Future that will resolve when the chunk is loaded
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public default java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(@NotNull Location loc) {
|
||||
+ return getChunkAtAsync((int)Math.floor(loc.getX()) >> 4, (int)Math.floor(loc.getZ()) >> 4, true, true);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * 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 future will always be executed synchronously
|
||||
+ * on the main Server Thread.
|
||||
+ * @param loc Location to load the corresponding chunk from
|
||||
+ * @param gen Should the chunk generate
|
||||
+ * @return Future that will resolve when the chunk is loaded
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public default java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(@NotNull Location loc, boolean gen) {
|
||||
+ return getChunkAtAsync((int)Math.floor(loc.getX()) >> 4, (int)Math.floor(loc.getZ()) >> 4, gen, true);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * 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 future will always be executed synchronously
|
||||
+ * on the main Server Thread.
|
||||
+ * @param block Block to load the corresponding chunk from
|
||||
+ * @return Future that will resolve when the chunk is loaded
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public default java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(@NotNull Block block) {
|
||||
+ return getChunkAtAsync(block.getX() >> 4, block.getZ() >> 4, true, true);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * 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 future will always be executed synchronously
|
||||
+ * on the main Server Thread.
|
||||
+ * @param block Block to load the corresponding chunk from
|
||||
+ * @param gen Should the chunk generate
|
||||
+ * @return Future that will resolve when the chunk is loaded
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public default java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(@NotNull Block block, boolean gen) {
|
||||
+ return getChunkAtAsync(block.getX() >> 4, block.getZ() >> 4, gen, true);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * 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 future will always be executed synchronously
|
||||
+ * on the main Server Thread.
|
||||
+ *
|
||||
+ * @param x X Coord
|
||||
+ * @param z Z Coord
|
||||
+ * @return Future that will resolve when the chunk is loaded
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public default java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(int x, int z) {
|
||||
+ return getChunkAtAsync(x, z, true, true);
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen, boolean urgent);
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
|
||||
index b4069dbf31587786da39f5e387a71b7bc6a5d0ae..45e0dffe60ce1f4d54b481b6b2cbee511659a5cc 100644
|
||||
index b4069dbf31587786da39f5e387a71b7bc6a5d0ae..b8e8a425a84a562ccd8431d30e39145a662c4180 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Entity.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Entity.java
|
||||
@@ -155,6 +155,30 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
|
||||
@@ -155,6 +155,33 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
|
||||
*/
|
||||
public boolean teleport(@NotNull Entity destination, @NotNull TeleportCause cause);
|
||||
|
||||
|
@ -397,7 +506,10 @@ index b4069dbf31587786da39f5e387a71b7bc6a5d0ae..45e0dffe60ce1f4d54b481b6b2cbee51
|
|||
+ @NotNull
|
||||
+ public default java.util.concurrent.CompletableFuture<Boolean> teleportAsync(@NotNull Location loc, @NotNull TeleportCause cause) {
|
||||
+ java.util.concurrent.CompletableFuture<Boolean> future = new java.util.concurrent.CompletableFuture<>();
|
||||
+ loc.getWorld().getChunkAtAsync(loc).thenAccept((chunk) -> future.complete(teleport(loc, cause)));
|
||||
+ loc.getWorld().getChunkAtAsyncUrgently(loc).thenAccept((chunk) -> future.complete(teleport(loc, cause))).exceptionally(ex -> {
|
||||
+ future.completeExceptionally(ex);
|
||||
+ return null;
|
||||
+ });
|
||||
+ return future;
|
||||
+ }
|
||||
+ // Paper end
|
||||
|
|
|
@ -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 b7ad4f566497914573ccfb595e660226dd34c273..c88f17244617b75e251811595ffc189dc81e12fb 100644
|
||||
index 42b91634a131f8705cbde96b6068d5881a393fb7..f9a5ea4fcdb87e741cf04b47d469e05f8a786155 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -1646,6 +1646,16 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@@ -1755,6 +1755,16 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
*/
|
||||
public void setFullTime(long time);
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@ persistenting Living Entity, SPAWNER for spawners,
|
|||
or DEFAULT since data was not stored.
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
|
||||
index 45e0dffe60ce1f4d54b481b6b2cbee511659a5cc..5518ecd21435334d9148cd3e095ec06031bdd0a5 100644
|
||||
index b8e8a425a84a562ccd8431d30e39145a662c4180..3f0f38031000a4eda25584d069939f40fbfb026b 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Entity.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Entity.java
|
||||
@@ -649,5 +649,11 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
|
||||
@@ -652,5 +652,11 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
|
||||
*/
|
||||
@NotNull
|
||||
Chunk getChunk();
|
||||
|
|
|
@ -5,10 +5,10 @@ Subject: [PATCH] World view distance api
|
|||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||
index db18f70ec37253232fb2cfd08ccd07d13c7c457d..421ad6a91ceb38fd62684d18f109d7cf8526605a 100644
|
||||
index 0a5865d85dfc28cb68f753878608b12afd74bc99..be4d6ca8e8ec4c2e6643eaecc19f11466e14658c 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -3166,6 +3166,34 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@@ -3275,6 +3275,34 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
int getViewDistance();
|
||||
// Spigot end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ Subject: [PATCH] Spawn Reason API
|
|||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||
index 421ad6a91ceb38fd62684d18f109d7cf8526605a..906ee6827dc6956b3c1657bde75ef8481e16dce2 100644
|
||||
index be4d6ca8e8ec4c2e6643eaecc19f11466e14658c..9518da825ed752c5a477ca9132de50f923f9192d 100644
|
||||
--- a/src/main/java/org/bukkit/World.java
|
||||
+++ b/src/main/java/org/bukkit/World.java
|
||||
@@ -1,6 +1,8 @@
|
||||
|
@ -17,7 +17,7 @@ index 421ad6a91ceb38fd62684d18f109d7cf8526605a..906ee6827dc6956b3c1657bde75ef848
|
|||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -2037,6 +2039,12 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@@ -2146,6 +2148,12 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@NotNull
|
||||
public <T extends Entity> T spawn(@NotNull Location location, @NotNull Class<T> clazz) throws IllegalArgumentException;
|
||||
|
||||
|
@ -30,7 +30,7 @@ index 421ad6a91ceb38fd62684d18f109d7cf8526605a..906ee6827dc6956b3c1657bde75ef848
|
|||
/**
|
||||
* Spawn an entity of a specific class at the given {@link Location}, with
|
||||
* the supplied function run before the entity is added to the world.
|
||||
@@ -2054,7 +2062,28 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@@ -2163,7 +2171,28 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
* {@link Entity} requested cannot be spawned
|
||||
*/
|
||||
@NotNull
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue