mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-24 09:58:00 +01:00
79e2cb620e
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 376e37db SPIGOT-7677: Update which entities are marked as spawnable 06c4add3 SPIGOT-7737: Add separate TreeType.MEGA_PINE 19b7caaa SPIGOT-7731: Spawn eggs cannot have damage e585297e PR-1022: Add force option to Player#spawnParticle d26e0094 PR-1018: Add methods to get players seeing specific chunks 8df1ed18 PR-978: Add Material#isCompostable and Material#getCompostChance 4b9b59c7 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale 8d1e700a PR-1020: Cast instead of using #typed when getting BlockType and ItemType to better work with testing / mocks fa28607a PR-1016: Fix incorrect assumption of Fireball having constant speed 4c6c8586 PR-1015: Add a tool component to ItemMeta 6f6b2123 PR-1014: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects f511cfe1 PR-1013, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType def44cbf SPIGOT-7669: Fix typo in ProjectileHitEvent#getHitBlockFace documentation 53fa4f72 PR-1011: Throw an exception if a RecipeChoice is ever supplied air CraftBukkit Changes: ee95e171a SPIGOT-7737: Add separate TreeType.MEGA_PINE 0dae4c62c Fix spawn egg equality check and copy constructor ab59e847c Fix spawn eggs with no entity creating invalid stacks and disconnect creative clients 3b6093b28 SPIGOT-7736: Creative spawn egg use loses components c6b4d5a87 SPIGOT-7731: Spawn eggs cannot have damage 340ccd57f SPIGOT-7735: Fix serialization of player heads with note block sound fd2f41834 SPIGOT-7734: Can't register a custom advancement using unsafe() 02456e2a5 PR-1413: Add force option to Player#spawnParticle 6a61f38b2 SPIGOT-7680: Per-world weather command 58c41cebb PR-1409: Add methods to get players seeing specific chunks 16c976797 PR-1412: Fix shipwreck loot tables not being set for BlockTransformers 7189ba636 PR-1360: Add Material#isCompostable and Material#getCompostChance 900384556 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale bdb40c5f1 Increase outdated build delay d6607c7dd SPIGOT-7675: Fix FoodComponent config deserialization b148ed332 PR-1406: Fix incorrect assumption of Fireball having constant speed 3ec31ca75 PR-1405: Add a tool component to ItemMeta 5d7d675b9 PR-1404: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects 960827981 PR-1403, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType 94e44ec93 PR-1401: Add a config option to accept old keys in registry get calls a43701920 PR-1402: Fix ChunkSnapshot#isSectionEmpty() is always false 87d0a3368 SPIGOT-7668: Move NONE Registry updater to FieldRename to avoid some class loader issues 2ea1e7ac2 PR-1399: Fix regression preventing positive .setDamage value from causing knockback for 0 damage events ba2d49d21 Increase outdated build delay Spigot Changes: fcd94e21 Rebuild patches 342f4939 SPIGOT-7661: Add experimental unload-frozen-chunks option
531 lines
24 KiB
Diff
531 lines
24 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Mon, 29 Feb 2016 17:43:33 -0600
|
|
Subject: [PATCH] Async Chunks API
|
|
|
|
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 1cc5bdd63a97a6bb62b1d29aca01658359bd15f1..6242b64416fdea1f3fd6378ba26ed7bb33ab4cc4 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
|
|
}
|
|
// Paper end - additional getNearbyEntities API
|
|
|
|
+ // Paper start - async chunks API
|
|
+ /**
|
|
+ * This is the Legacy API before Java 8 was supported. Java 8 Consumer is provided,
|
|
+ * as well as future support
|
|
+ *
|
|
+ * Used by {@link World#getChunkAtAsync(Location,ChunkLoadCallback)} methods
|
|
+ * to request a {@link Chunk} to be loaded, with this callback receiving
|
|
+ * the chunk when it is finished.
|
|
+ *
|
|
+ * This callback will be executed on synchronously on the main thread.
|
|
+ *
|
|
+ * Timing and order this callback is fired is intentionally not defined and
|
|
+ * and subject to change.
|
|
+ *
|
|
+ * @deprecated Use either the Future or the Consumer based methods
|
|
+ */
|
|
+ @Deprecated(since = "1.13.1")
|
|
+ public static interface ChunkLoadCallback extends java.util.function.Consumer<Chunk> {
|
|
+ public void onLoad(@NotNull Chunk chunk);
|
|
+
|
|
+ // backwards compat to old api
|
|
+ @Override
|
|
+ default void accept(@NotNull Chunk chunk) {
|
|
+ onLoad(chunk);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * 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 ChunkLoadCallback} will always be executed synchronously
|
|
+ * on the main Server Thread.
|
|
+ *
|
|
+ * @deprecated Use either the Future or the Consumer based methods
|
|
+ * @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 cb Callback to receive the chunk when it is loaded.
|
|
+ * will be executed synchronously
|
|
+ */
|
|
+ @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;
|
|
+ });
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Requests a {@link Chunk} to be loaded at the given {@link Location}
|
|
+ *
|
|
+ * 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 ChunkLoadCallback} will always be executed synchronously
|
|
+ * on the main Server Thread.
|
|
+ *
|
|
+ * @deprecated Use either the Future or the Consumer based methods
|
|
+ * @param loc Location of the chunk
|
|
+ * @param cb Callback to receive the chunk when it is loaded.
|
|
+ * will be executed synchronously
|
|
+ */
|
|
+ @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;
|
|
+ });
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Requests {@link Chunk} to be loaded that contains the given {@link Block}
|
|
+ *
|
|
+ * 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 ChunkLoadCallback} will always be executed synchronously
|
|
+ * on the main Server Thread.
|
|
+ *
|
|
+ * @deprecated Use either the Future or the Consumer based methods
|
|
+ * @param block Block to get the containing chunk from
|
|
+ * @param cb Callback to receive the chunk when it is loaded.
|
|
+ * will be executed synchronously
|
|
+ */
|
|
+ @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;
|
|
+ });
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * 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 cb Callback to receive the chunk when it is loaded.
|
|
+ * 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;
|
|
+ });
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * 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 cb Callback to receive the chunk when it is loaded.
|
|
+ * 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;
|
|
+ });
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Requests a {@link Chunk} to be loaded at the given {@link Location}
|
|
+ *
|
|
+ * 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 loc Location of the chunk
|
|
+ * @param cb Callback to receive the chunk when it is loaded.
|
|
+ * will be executed synchronously
|
|
+ */
|
|
+ default void getChunkAtAsync(final @NotNull Location loc, final @NotNull Consumer<? super Chunk> cb) {
|
|
+ this.getChunkAtAsync((int) Math.floor(loc.getX()) >> 4, (int) Math.floor(loc.getZ()) >> 4, true, 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,
|
|
+ * 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 loc Location of the chunk
|
|
+ * @param gen Should the chunk generate if it doesn't exist
|
|
+ * @param cb Callback to receive the chunk when it is loaded.
|
|
+ * will be executed synchronously
|
|
+ */
|
|
+ default void getChunkAtAsync(final @NotNull Location loc, final boolean gen, final @NotNull Consumer<? super Chunk> cb) {
|
|
+ this.getChunkAtAsync((int) Math.floor(loc.getX()) >> 4, (int) Math.floor(loc.getZ()) >> 4, gen, cb);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Requests {@link Chunk} to be loaded that contains the given {@link Block}
|
|
+ *
|
|
+ * 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 block Block to get the containing chunk from
|
|
+ * @param cb Callback to receive the chunk when it is loaded.
|
|
+ * will be executed synchronously
|
|
+ */
|
|
+ default void getChunkAtAsync(final @NotNull Block block, final @NotNull Consumer<? super Chunk> cb) {
|
|
+ this.getChunkAtAsync(block.getX() >> 4, block.getZ() >> 4, true, cb);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Requests {@link Chunk} to be loaded that contains the given {@link Block}
|
|
+ *
|
|
+ * 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 block Block to get the containing chunk from
|
|
+ * @param gen Should the chunk generate if it doesn't exist
|
|
+ * @param cb Callback to receive the chunk when it is loaded.
|
|
+ * will be executed synchronously
|
|
+ */
|
|
+ default void getChunkAtAsync(final @NotNull Block block, final boolean gen, final @NotNull Consumer<? super Chunk> cb) {
|
|
+ this.getChunkAtAsync(block.getX() >> 4, block.getZ() >> 4, gen, 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 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
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(final @NotNull Location loc) {
|
|
+ return this.getChunkAtAsync((int) Math.floor(loc.getX()) >> 4, (int) Math.floor(loc.getZ()) >> 4, 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 if it doesn't exist
|
|
+ * @return Future that will resolve when the chunk is loaded
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(final @NotNull Location loc, final boolean gen) {
|
|
+ return this.getChunkAtAsync((int) Math.floor(loc.getX()) >> 4, (int) Math.floor(loc.getZ()) >> 4, gen);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * 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
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(final @NotNull Block block) {
|
|
+ return this.getChunkAtAsync(block.getX() >> 4, block.getZ() >> 4, 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 if it doesn't exist
|
|
+ * @return Future that will resolve when the chunk is loaded
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(final @NotNull Block block, final boolean gen) {
|
|
+ return this.getChunkAtAsync(block.getX() >> 4, block.getZ() >> 4, gen);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * 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 Chunk X-coordinate of the chunk - floor(world coordinate / 16)
|
|
+ * @param z Chunk Z-coordinate of the chunk - floor(world coordinate / 16)
|
|
+ * @return Future that will resolve when the chunk is loaded
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(final int x, final int z) {
|
|
+ return this.getChunkAtAsync(x, z, 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 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
|
|
+ * @return Future that will resolve when the chunk is loaded
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(final int x, final int z, final boolean gen) {
|
|
+ return this.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
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(final @NotNull Location loc) {
|
|
+ return this.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 if it doesn't exist
|
|
+ * @return Future that will resolve when the chunk is loaded
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(final @NotNull Location loc, final boolean gen) {
|
|
+ return this.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
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(final @NotNull Block block) {
|
|
+ return this.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 if it doesn't exist
|
|
+ * @return Future that will resolve when the chunk is loaded
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(final @NotNull Block block, final boolean gen) {
|
|
+ return this.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
|
|
+ */
|
|
+ default @NotNull java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsyncUrgently(final int x, final int z) {
|
|
+ return this.getChunkAtAsync(x, z, true, true);
|
|
+ }
|
|
+
|
|
+ java.util.concurrent.@NotNull CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen, boolean urgent);
|
|
+ // Paper end - async chunks API
|
|
+
|
|
/**
|
|
* Get a list of all players in this World
|
|
*
|
|
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
|
|
index 48177547ec93fb5a807897a6fb472582a78f3978..99e1f17fddf9cebe7057998d1635804c55f18312 100644
|
|
--- a/src/main/java/org/bukkit/entity/Entity.java
|
|
+++ b/src/main/java/org/bukkit/entity/Entity.java
|
|
@@ -168,6 +168,39 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
|
|
*/
|
|
public boolean teleport(@NotNull Entity destination, @NotNull TeleportCause cause);
|
|
|
|
+ // Paper start
|
|
+ /**
|
|
+ * Loads/Generates(in 1.13+) the Chunk asynchronously, and then teleports the entity when the chunk is ready.
|
|
+ * @param loc Location to teleport to
|
|
+ * @return A future that will be completed with the result of the teleport
|
|
+ */
|
|
+ default java.util.concurrent.@NotNull CompletableFuture<Boolean> teleportAsync(final @NotNull Location loc) {
|
|
+ return this.teleportAsync(loc, TeleportCause.PLUGIN);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Loads/Generates(in 1.13+) the Chunk asynchronously, and then teleports the entity when the chunk is ready.
|
|
+ * @param loc Location to teleport to
|
|
+ * @param cause Reason for teleport
|
|
+ * @return A future that will be completed with the result of the teleport
|
|
+ */
|
|
+ default java.util.concurrent.@NotNull CompletableFuture<Boolean> teleportAsync(final @NotNull Location loc, final @NotNull TeleportCause cause) {
|
|
+ final class Holder {
|
|
+ static final io.papermc.paper.entity.TeleportFlag[] EMPTY_FLAGS = new io.papermc.paper.entity.TeleportFlag[0];
|
|
+ }
|
|
+ return this.teleportAsync(loc, cause, Holder.EMPTY_FLAGS);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Loads/Generates(in 1.13+) the Chunk asynchronously, and then teleports the entity when the chunk is ready.
|
|
+ * @param loc Location to teleport to
|
|
+ * @param cause Reason for teleport
|
|
+ * @param teleportFlags Flags to be used in this teleportation
|
|
+ * @return A future that will be completed with the result of the teleport
|
|
+ */
|
|
+ java.util.concurrent.@NotNull CompletableFuture<Boolean> teleportAsync(@NotNull Location loc, @NotNull TeleportCause cause, @NotNull io.papermc.paper.entity.TeleportFlag @NotNull... teleportFlags);
|
|
+ // Paper end
|
|
+
|
|
/**
|
|
* Returns a list of entities within a bounding box centered around this
|
|
* entity
|