feat: Entity#teleportAsync method with TeleportFlags (#10371)

* feat: Entity#teleportAsync method with TeleportFlags

* use method-local class

---------

Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
Bridge 2024-04-06 22:38:37 +02:00 committed by GitHub
parent bd38e0318a
commit a774fbaca8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 160 additions and 144 deletions

View File

@ -485,10 +485,10 @@ index 8bef6168caf0932a5a64cf69eb7988fa3191b13a..ab183821b93dcfed1e881b481f0a3166
* 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 57a1d07d0430019fd38c72b9f58c7145927ecd02..a0ed358156f9cbeb9e3cbb910ac17785edd30152 100644
index 57a1d07d0430019fd38c72b9f58c7145927ecd02..8a7a4a8cf5f0b88664859cd43b0b01e6d261715d 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -168,6 +168,33 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -168,6 +168,39 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
public boolean teleport(@NotNull Entity destination, @NotNull TeleportCause cause);
@ -498,25 +498,31 @@ index 57a1d07d0430019fd38c72b9f58c7145927ecd02..a0ed358156f9cbeb9e3cbb910ac17785
+ * @param loc Location to teleport to
+ * @return A future that will be completed with the result of the teleport
+ */
+ @NotNull
+ public default java.util.concurrent.CompletableFuture<Boolean> teleportAsync(@NotNull Location loc) {
+ return teleportAsync(loc, TeleportCause.PLUGIN);
+ 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
+ */
+ @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().getChunkAtAsyncUrgently(loc).thenAccept((chunk) -> future.complete(teleport(loc, cause))).exceptionally(ex -> {
+ future.completeExceptionally(ex);
+ return null;
+ });
+ return future;
+ 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
+
/**

View File

@ -12,10 +12,10 @@ or DEFAULT since data was not stored.
Co-authored-by: Aurora <aurora@relanet.eu>
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index a0ed358156f9cbeb9e3cbb910ac17785edd30152..8a01590cc0ee7517dc4c2a52e95aad2680610a43 100644
index 8a7a4a8cf5f0b88664859cd43b0b01e6d261715d..11a77f977c6abc031cf5a4d58924bc7af5e7ea53 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -836,5 +836,11 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -842,5 +842,11 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
// TODO remove impl here
return getLocation().getChunk();
}

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Add entity liquid API
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 8a01590cc0ee7517dc4c2a52e95aad2680610a43..4d6d75387b9a3ec467982e17a5131cd10f302260 100644
index 11a77f977c6abc031cf5a4d58924bc7af5e7ea53..3deccdf110c2cb74444b5d715082fbbdaa8f20ce 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -842,5 +842,40 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -848,5 +848,40 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
@NotNull
org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason();

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Entity#isTicking
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 4d6d75387b9a3ec467982e17a5131cd10f302260..56e3a0649089e2546658144a3f09135be3a4e5e8 100644
index 3deccdf110c2cb74444b5d715082fbbdaa8f20ce..9711a8077238383f23fb7aa2c20b2c089776e3f8 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -877,5 +877,10 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -883,5 +883,10 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
* Check if entity is in lava
*/
boolean isInLava();

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Expose Tracked Players
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 56e3a0649089e2546658144a3f09135be3a4e5e8..d68ccecaadcf7a906058e66a750f4cfce5dd7b3f 100644
index 9711a8077238383f23fb7aa2c20b2c089776e3f8..b32683b5e4431950d9dccec3ae11f6377c7b0da7 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -882,5 +882,14 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -888,5 +888,14 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
* Check if entity is inside a ticking chunk
*/
boolean isTicking();

View File

@ -417,10 +417,10 @@ index 9e7f42caab1204036f4203354c115fd40c6def92..138d2530de2410f4a9424dabd3e5ce0c
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index d68ccecaadcf7a906058e66a750f4cfce5dd7b3f..578c22b0aef9c89a3c33b75c33bcdc60bdab6b49 100644
index b32683b5e4431950d9dccec3ae11f6377c7b0da7..b2466aa08ebb26f3a5edd6a4b2c7e12f7a90ef0a 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -283,6 +283,40 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -289,6 +289,40 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
boolean isFrozen();
@ -585,7 +585,7 @@ index 6b3c9bef9a8a34ddc6ff42cf358541a2665bf5e3..9c618a27d590f186f29c5d9094fc565e
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index 99f314f25d1d6118e0884822d428c47060373bec..13eb80455dd589e87c39a7a5570ef093c7660205 100644
index a253ac2b60b038177e6c4f20d8367be36f10b1bd..2036e7b464f631054abb94333a8674d31bdce800 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -992,6 +992,7 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource

View File

@ -24,10 +24,10 @@ index ca0b126bff245ed3fe69bc49c28499f7a7aa9556..6426d8585bba71b3e998b1eb078ac0fc
* Creates and returns the next EntityId available.
* <p>
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 578c22b0aef9c89a3c33b75c33bcdc60bdab6b49..621ee3fd49ee96143df2f24889e9aef74448a544 100644
index b2466aa08ebb26f3a5edd6a4b2c7e12f7a90ef0a..d4f84318265343242a9fca565e456c7a8c1d68f7 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -925,5 +925,32 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -931,5 +931,32 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
@Deprecated
@NotNull Set<Player> getTrackedPlayers();

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Entity powdered snow API
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 9cb84eababf159b04618a605ff03cdaee72c9502..a7b37ba26d8999a78a747fe5a41e15327ae3a2ee 100644
index d4f84318265343242a9fca565e456c7a8c1d68f7..6db147a2330e8046c1bfb5ec2acd8dd30827d475 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -952,5 +952,12 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -958,5 +958,12 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
* @return Whether the entity was successfully spawned.
*/
public boolean spawnAt(@NotNull Location location, @NotNull org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason);

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Freeze Tick Lock API
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index a7b37ba26d8999a78a747fe5a41e15327ae3a2ee..9b5fe55399594c57c1b1521bea03781fd99fdf60 100644
index 6db147a2330e8046c1bfb5ec2acd8dd30827d475..8827defeb26593cb2c2391e505b008f1190b01f3 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -317,6 +317,26 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -323,6 +323,26 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
boolean hasNoPhysics();
// Paper end - missing entity api

View File

@ -25,10 +25,10 @@ index 44ee56a5956cc17194c767a0c1071a2abffe818a..43dd6c59cceba12f27e6b265acc3ad97
// Paper end
}
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index e2f315db8d137d7bc1b6fc83ed29032152f881f2..4951afd12de6145f671bae40a4df6e2222bc3fd8 100644
index bc1547381b08d1acbbef885d9c3ecd63f3550426..8e2fa4dba0337a175acfee24fc59423ab4714977 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -1002,4 +1002,26 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -1008,4 +1008,26 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
boolean isInPowderedSnow();
// Paper end

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Add Sneaking API for Entities
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 4951afd12de6145f671bae40a4df6e2222bc3fd8..909926485a66e09988f7787b1d5ee2cf9c012558 100644
index 8e2fa4dba0337a175acfee24fc59423ab4714977..2d6f7b2bf4cb23ef43a4dcbab2ecd2a7c7c2809c 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -813,6 +813,25 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -819,6 +819,25 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@NotNull
Pose getPose();

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Add Entity Body Yaw API
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index d6e4c7cdd34b03295825b3c5ad76626f8f48ec0e..11df702c6f8282aa96ae1ed6b9b29c81fbfadbad 100644
index 2d6f7b2bf4cb23ef43a4dcbab2ecd2a7c7c2809c..0be4107270fb7fdba5c7d0e6f3964d33337f91f0 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -1020,6 +1020,43 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -1026,6 +1026,43 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
* @return true if in powdered snow.
*/
boolean isInPowderedSnow();

View File

@ -769,10 +769,10 @@ index d433a9d2fe0bb487865fec33307cc4c45af475a0..f819de247080d58803a2851a4cab28d2
+ // Paper end - Folia region threading API
}
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 17d5a5458ee51d8db243326745875ef31ba95fb3..05076e0648407d026b3adba43756e57f7e925abe 100644
index 0be4107270fb7fdba5c7d0e6f3964d33337f91f0..c01c3f6576d4c0a8a173080ce01509d3eb678611 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -1080,4 +1080,15 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -1086,4 +1086,15 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
boolean wouldCollideUsing(@NotNull BoundingBox boundingBox);
// Paper end - Collision API

View File

@ -7,10 +7,10 @@ Was obtainable through different methods, but you had to use different
methods depending on the implementation of Entity you were working with.
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 05076e0648407d026b3adba43756e57f7e925abe..a7045fdf70e7dac94034ed6727a4eb29f31a9cdf 100644
index c01c3f6576d4c0a8a173080ce01509d3eb678611..2a30cda9efb24829f9c6a265e8be2dd848fa7c7c 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -1091,4 +1091,15 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -1097,4 +1097,15 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
@NotNull io.papermc.paper.threadedregions.scheduler.EntityScheduler getScheduler();
// Paper end - Folia schedulers

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Expand Pose API
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index a7045fdf70e7dac94034ed6727a4eb29f31a9cdf..66f9e50d96710a41ac009271a499318fcf119c54 100644
index 2a30cda9efb24829f9c6a265e8be2dd848fa7c7c..23def071492ccd715693d534cc506936e18f0f46 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -830,6 +830,42 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -836,6 +836,42 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
* @param sneak true if the entity should be sneaking
*/
void setSneaking(boolean sneak);

View File

@ -7850,48 +7850,6 @@ index 0630680d1ff7ffd2e9c323a800213b1137817642..f012ba9c55241afb159136e8b55e7740
+ public void setSendViewDistance(final int viewDistance) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index f5a5496e21e29c6ae9f497f5939823078ac8c1c0..7126d8cdeea5eb23176af6a97a99b33961749d71 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -898,4 +898,37 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return this.spigot;
}
// Spigot end
+
+ // Paper start
+ @Override
+ public java.util.concurrent.CompletableFuture<Boolean> teleportAsync(Location location, TeleportCause cause) {
+ Preconditions.checkArgument(location != null, "location");
+ location.checkFinite();
+ Location locationClone = location.clone(); // clone so we don't need to worry about mutations after this call.
+
+ net.minecraft.server.level.ServerLevel world = ((CraftWorld)locationClone.getWorld()).getHandle();
+ java.util.concurrent.CompletableFuture<Boolean> ret = new java.util.concurrent.CompletableFuture<>();
+
+ world.loadChunksForMoveAsync(getHandle().getBoundingBoxAt(locationClone.getX(), locationClone.getY(), locationClone.getZ()),
+ this instanceof CraftPlayer ? ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.HIGHER : ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.NORMAL, (list) -> {
+ net.minecraft.server.level.ServerChunkCache chunkProviderServer = world.getChunkSource();
+ for (net.minecraft.world.level.chunk.ChunkAccess chunk : list) {
+ chunkProviderServer.addTicketAtLevel(net.minecraft.server.level.TicketType.POST_TELEPORT, chunk.getPos(), 33, CraftEntity.this.getEntityId());
+ }
+ net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(() -> {
+ try {
+ ret.complete(CraftEntity.this.teleport(locationClone, cause) ? Boolean.TRUE : Boolean.FALSE);
+ } catch (Throwable throwable) {
+ if (throwable instanceof ThreadDeath) {
+ throw (ThreadDeath)throwable;
+ }
+ net.minecraft.server.MinecraftServer.LOGGER.error("Failed to teleport entity " + CraftEntity.this, throwable);
+ ret.completeExceptionally(throwable);
+ }
+ });
+ });
+
+ return ret;
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java

View File

@ -25,7 +25,7 @@ index 13725b794e923a4de0d06edcba1adf1b04611c95..4c0e12d9f36c78eeae4dcb2f58d41503
public void onTrackingEnd(Entity entity) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index cdb4acbaf019608c57d7a40c6928ddc9c00fd1d5..c21c4d6df21bc9741f087ac4a328aad04b1cda38 100644
index 360e322ee298048bd280160a49f000384d930c3a..6f687387d8f817646dacf0e0373d50db8ee80dd5 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -320,7 +320,27 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@ -94,14 +94,15 @@ index cdb4acbaf019608c57d7a40c6928ddc9c00fd1d5..c21c4d6df21bc9741f087ac4a328aad0
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index e78a378f0de48cde3702774970e6cda241b8ddda..6871fe86c9cda00d0187f3df827772200eca1bcc 100644
index 0f51f05f334d262b3435cebce47c3b9f08936398..85d77772b003e56382f8c3b55fc11a9ae1ec535f 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -968,5 +968,20 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return ret;
@@ -936,4 +936,21 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return this.spigot;
}
// Spigot end
+
+ // Paper start - entity origin API
+ @Override
+ public Location getOrigin() {
+ Vector originVector = this.getHandle().getOriginVector();
@ -116,5 +117,5 @@ index e78a378f0de48cde3702774970e6cda241b8ddda..6871fe86c9cda00d0187f3df82777220
+ //noinspection ConstantConditions
+ return originVector.toLocation(world);
+ }
// Paper end
+ // Paper end - entity origin API
}

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Entity#fromMobSpawner()
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index c261971ab482abfa5a1ca51abd189eff16421534..fe314015f8cbc44e29a8ec73ecca4eeadd1da39f 100644
index 6d31ced629fabef4de2ef9a26586cea0cffa155c..0cc82ffdcebbdd92fa953e7c52a20911f46a503c 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -395,6 +395,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@ -49,17 +49,18 @@ index a46293dafeb73f9206b92a2850df18a6a5f688b4..487e4211d6486d2b3052c931c27cee97
if (org.bukkit.craftbukkit.event.CraftEventFactory.callSpawnerSpawnEvent(entity, pos).isCancelled()) {
continue;
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 4a875d038f1ab7f2bdc5f290a6ad71e4b61c6822..d715dcc9155ad9938bd4fbe0cde43079f614f203 100644
index 1be5c322abcec8ec32b84dec02d386e53cb5e16a..4808c62d3d951b201061659c91d1001e4b9b49ef 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1013,5 +1013,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
//noinspection ConstantConditions
@@ -983,4 +983,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return originVector.toLocation(world);
}
// Paper end - entity origin API
+
+ // Paper start - Entity#fromMobSpawner
+ @Override
+ public boolean fromMobSpawner() {
+ return getHandle().spawnedViaMobSpawner;
+ return this.getHandle().spawnedViaMobSpawner;
+ }
// Paper end
+ // Paper end - Entity#fromMobSpawner
}

View File

@ -59,7 +59,7 @@ index 28b81e29be07902ad4d04aeb18bffd49757c3029..bc440f9a239d3935bf6837edf815d4fd
});
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index cb453b843ecf82454a8ade369d424d5e7bbda4c4..92521a46de31b13812d82a844ddc178df2b34919 100644
index f746829f1e94ee58821e56ec4192269add00395b..257be4dd3f38c089dd970b9ac6f292b4f010a01c 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -238,6 +238,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@ -133,17 +133,18 @@ index faad948f089575e4988d989790cc1dd13f8a79cd..e143f42e71ac774d49b75e6d85591aa1
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 34e4dd733a2e9ccc3c7f1b228825428100e583e9..d898b26d6d9c6999aa645f201bdbbd6e30073c0f 100644
index 6fddbcec673564ac531a852f631f6acc460accbd..9ed122efb2b380bb2c1b50fdfe75bf3e679c9c6e 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1019,5 +1019,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
public boolean fromMobSpawner() {
return getHandle().spawnedViaMobSpawner;
@@ -991,4 +991,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return this.getHandle().spawnedViaMobSpawner;
}
// Paper end - Entity#fromMobSpawner
+
+ // Paper start - entity spawn reason API
+ @Override
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason() {
+ return getHandle().spawnReason;
+ }
// Paper end
+ // Paper end - entity spawn reason API
}

View File

@ -8,14 +8,15 @@ public net.minecraft.world.entity.Entity isInRain()Z
public net.minecraft.world.entity.Entity isInBubbleColumn()Z
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index d898b26d6d9c6999aa645f201bdbbd6e30073c0f..061b7215a678c8ec563bdb9c2a8beb65061faf0e 100644
index 9ed122efb2b380bb2c1b50fdfe75bf3e679c9c6e..326978aedbd9cc81db2bf1d5398c1cd2ce68a866 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1024,5 +1024,40 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason() {
@@ -998,4 +998,41 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return getHandle().spawnReason;
}
// Paper end - entity spawn reason API
+
+ // Paper start - entity liquid API
+ @Override
+ public boolean isUnderWater() {
+ return getHandle().isUnderWater();
@ -50,5 +51,5 @@ index d898b26d6d9c6999aa645f201bdbbd6e30073c0f..061b7215a678c8ec563bdb9c2a8beb65
+ public boolean isInLava() {
+ return getHandle().isInLava();
+ }
// Paper end
+ // Paper end - entity liquid API
}

View File

@ -19,17 +19,18 @@ index 44610d4e3fb69e6cf5629d9e895e93d8dd5e09e9..2c0c41ae455ae5894e6bd85830741143
// Paper end - Expose entity id counter
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index c8033bde8976c128da832befe4225238737a992a..103e8707ae9434c8e60059f75dafdd9e0fcc8b39 100644
index f664fd4aa8d79e95787848b5a3e0ed7bc182fa25..ef8f8b3f97405250ebe058c67c4099da66a8e773 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1059,5 +1059,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
public boolean isInLava() {
@@ -1035,4 +1035,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return getHandle().isInLava();
}
// Paper end - entity liquid API
+
+ // Paper start - isTicking API
+ @Override
+ public boolean isTicking() {
+ return getHandle().isTicking();
+ }
// Paper end
+ // Paper end - isTicking API
}

View File

@ -5,14 +5,15 @@ Subject: [PATCH] Expose Tracked Players
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 103e8707ae9434c8e60059f75dafdd9e0fcc8b39..07158732dd6a5b7d622b7f2ea10ca87b50365b8a 100644
index ef8f8b3f97405250ebe058c67c4099da66a8e773..524d3118663f5531e530dcdfa5da4ded2415468f 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1064,5 +1064,18 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
public boolean isTicking() {
@@ -1042,4 +1042,19 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return getHandle().isTicking();
}
// Paper end - isTicking API
+
+ // Paper start - tracked players API
+ @Override
+ public Set<org.bukkit.entity.Player> getTrackedPlayers() {
+ if (this.entity.tracker == null) {
@ -25,5 +26,5 @@ index 103e8707ae9434c8e60059f75dafdd9e0fcc8b39..07158732dd6a5b7d622b7f2ea10ca87b
+ }
+ return set;
+ }
// Paper end
+ // Paper end - tracked players API
}

View File

@ -671,13 +671,13 @@ index fc0f0e841dc974d080e1abb9bbafb5165801131f..d657fd2c507a5b215aeab0a5f3e9c2ee
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 07158732dd6a5b7d622b7f2ea10ca87b50365b8a..ebbefcdea6356384f27e964bd551bad2f9e696e8 100644
index 524d3118663f5531e530dcdfa5da4ded2415468f..65ce8ab201e7e36f6d2637e906af325e11e425dd 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1078,4 +1078,27 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
@@ -1057,4 +1057,27 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return set;
}
// Paper end
// Paper end - tracked players API
+
+ // Paper start - missing entity api
+ @Override
@ -796,7 +796,7 @@ index 2cec61a1bb050c1ef81c5fc3d0afafe9ff29d459..97fa4e1e70203194bd939618b2fad926
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index aaacc38b0b2dd435ef5cb6a934cfcd6659c4ca15..9c69fe09b2cf1172fe0e16f6799cc67bc0ccd397 100644
index 0a039d3ce686b7e47361c60f141943b621898707..e2a566c4f9402fe035c3363faff84e49956a536b 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -921,14 +921,29 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {

View File

@ -27,14 +27,14 @@ index 7dbbf0884b70acb37c3400364736fa8f6b68c964..5dce3d38ecd7b7639f02f3e1e92f3723
return this.isPassenger() ? false : this.saveAsPassenger(nbt);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index ebbefcdea6356384f27e964bd551bad2f9e696e8..06febdb103f98dd16cca32d7345b0ca6b52dcade 100644
index 65ce8ab201e7e36f6d2637e906af325e11e425dd..c819fa8e5b69c23558a89b68f9a5a31e1b233ca3 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1077,6 +1077,16 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
return set;
@@ -1058,6 +1058,18 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
+
// Paper end - tracked players API
+ // Paper start - raw entity serialization API
+ @Override
+ public boolean spawnAt(Location location, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ Preconditions.checkNotNull(location, "location cannot be null");
@ -44,9 +44,11 @@ index ebbefcdea6356384f27e964bd551bad2f9e696e8..06febdb103f98dd16cca32d7345b0ca6
+ this.entity.setRot(location.getYaw(), location.getPitch());
+ return !this.entity.valid && this.entity.level().addFreshEntity(this.entity, reason);
+ }
// Paper end
+ // Paper end - raw entity serialization API
+
// Paper start - missing entity api
@Override
public boolean isInvisible() { // Paper - moved up from LivingEntity
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index 2734f4187a4b92ef461e1f2fdae9139c6f54d8fc..be82e1d52d7026facb20bf07f4b3a394e77ab708 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java

View File

@ -7,21 +7,23 @@ Subject: [PATCH] Entity powdered snow API
public net.minecraft.world.entity.monster.Skeleton inPowderSnowTime
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 06febdb103f98dd16cca32d7345b0ca6b52dcade..8f0df02a81c36244a3906efa6605f5eba030bfb9 100644
index c819fa8e5b69c23558a89b68f9a5a31e1b233ca3..25c064a7da80ef98a758d7cb8bd1aa3de452e2e4 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1087,6 +1087,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
this.entity.setRot(location.getYaw(), location.getPitch());
return !this.entity.valid && this.entity.level().addFreshEntity(this.entity, reason);
@@ -1070,6 +1070,13 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
+
// Paper end - raw entity serialization API
+ // Paper start - entity powdered snow API
+ @Override
+ public boolean isInPowderedSnow() {
+ return getHandle().isInPowderSnow || getHandle().wasInPowderSnow; // depending on the location in the entity "tick" either could be needed.
+ }
// Paper end
+ // Paper end - entity powdered snow API
+
// Paper start - missing entity api
@Override
public boolean isInvisible() { // Paper - moved up from LivingEntity
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeleton.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeleton.java
index a0ea54181de6c6685deef265cbe9f66aabbca42b..6f98da9be6aef35e3b5c940188b872459a383c8e 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeleton.java

View File

@ -29,7 +29,7 @@ index 5775d071f714e7b9d959bfa94510b865f489e68e..27eb4bc4d1276ea36b97d0faeed2acee
d0 = to.getX();
d1 = to.getY();
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 88e05b8ec5f442b3ad14e3b39a06beeca5c169ae..70c1b20c2b25fbe53255f1753d86570c975767ab 100644
index 46bc34741394740de46546bd4ce7db35c757316c..79e58d7a72a599cd84d479be62f72c523e37dd07 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -219,15 +219,36 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
@ -71,6 +71,46 @@ index 88e05b8ec5f442b3ad14e3b39a06beeca5c169ae..70c1b20c2b25fbe53255f1753d86570c
// Let the server handle cross world teleports
if (location.getWorld() != null && !location.getWorld().equals(this.getWorld())) {
@@ -948,6 +969,39 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return CraftEntity.perm;
}
+ // Paper start - more teleport API / async chunk API
+ @Override
+ public java.util.concurrent.CompletableFuture<Boolean> teleportAsync(final Location location, final TeleportCause cause, final io.papermc.paper.entity.TeleportFlag... teleportFlags) {
+ Preconditions.checkArgument(location != null, "location");
+ location.checkFinite();
+ Location locationClone = location.clone(); // clone so we don't need to worry about mutations after this call.
+
+ net.minecraft.server.level.ServerLevel world = ((CraftWorld)locationClone.getWorld()).getHandle();
+ java.util.concurrent.CompletableFuture<Boolean> ret = new java.util.concurrent.CompletableFuture<>();
+
+ world.loadChunksForMoveAsync(getHandle().getBoundingBoxAt(locationClone.getX(), locationClone.getY(), locationClone.getZ()),
+ this instanceof CraftPlayer ? ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.HIGHER : ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.NORMAL, (list) -> {
+ net.minecraft.server.level.ServerChunkCache chunkProviderServer = world.getChunkSource();
+ for (net.minecraft.world.level.chunk.ChunkAccess chunk : list) {
+ chunkProviderServer.addTicketAtLevel(net.minecraft.server.level.TicketType.POST_TELEPORT, chunk.getPos(), 33, CraftEntity.this.getEntityId());
+ }
+ net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(() -> {
+ try {
+ ret.complete(CraftEntity.this.teleport(locationClone, cause, teleportFlags) ? Boolean.TRUE : Boolean.FALSE);
+ } catch (Throwable throwable) {
+ if (throwable instanceof ThreadDeath) {
+ throw (ThreadDeath)throwable;
+ }
+ net.minecraft.server.MinecraftServer.LOGGER.error("Failed to teleport entity " + CraftEntity.this, throwable);
+ ret.completeExceptionally(throwable);
+ }
+ });
+ });
+
+ return ret;
+ }
+ // Paper end - more teleport API / async chunk API
+
// Spigot start
private final org.bukkit.entity.Entity.Spigot spigot = new org.bukkit.entity.Entity.Spigot()
{
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 11e144bf561cc3c4dc1d8b712f915cc167f4d4ed..f606250106f1bcf5870dff1167f2902f85f7784a 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java

View File

@ -22,10 +22,10 @@ index fbcf1320ef9c1817b24aa8724cd6cf07319c20b9..5680e9772a2d90e997d2d0aacdda9edd
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 70c1b20c2b25fbe53255f1753d86570c975767ab..254df37281a358cc0ac99b46f34daf2fd9774d5a 100644
index 79e58d7a72a599cd84d479be62f72c523e37dd07..f6d6b2c7aefc39a6e6e2b0e61fd9afb334bee764 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1148,4 +1148,20 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
@@ -1164,4 +1164,20 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return this.getHandle().noPhysics;
}
// Paper end - missing entity api

View File

@ -5,14 +5,14 @@ Subject: [PATCH] Add Entity Body Yaw API
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index b4ed7612a019a3d4d473dfbfed2067ea437fee06..509550bbfb7c6bcff5dffa535f40af12aab898a8 100644
index 4dfbcaba4615bd761c1eb9d5994168c7202fc571..8025b3e9afebc9ad0c08453403422589bf5dd27d 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1136,6 +1136,31 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
public boolean isInPowderedSnow() {
return getHandle().isInPowderSnow || getHandle().wasInPowderSnow; // depending on the location in the entity "tick" either could be needed.
@@ -1154,6 +1154,33 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
+
// Paper end - entity powdered snow API
+ // Paper start - entity body yaw API
+ @Override
+ public double getX() {
+ return this.entity.getX();
@ -37,9 +37,11 @@ index b4ed7612a019a3d4d473dfbfed2067ea437fee06..509550bbfb7c6bcff5dffa535f40af12
+ public float getYaw() {
+ return this.entity.getBukkitYaw();
+ }
// Paper end
+ // Paper end - entity body yaw API
+
// Paper start - missing entity api
@Override
public boolean isInvisible() { // Paper - moved up from LivingEntity
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 9c5ad1ffdd82ce5d12eabca07f45a37e6a939f2e..ec62e68686b7c46df299d946850ec60631ecc6be 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java

View File

@ -7,10 +7,10 @@ Was obtainable through different methods, but you had to use different
methods depending on the implementation of Entity you were working with.
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 8086eae45b03fd53bc7cac625b51fc10d8523f4f..d91d56175e91fb06138901bad56c1c2544b3d20e 100644
index a47d3dba348a058ea9ca675b7f6490a46c1ad970..cbcfb0bc3a85b60e13014245f256e5c356b4b79b 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1216,4 +1216,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
@@ -1234,4 +1234,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return !this.getHandle().level().noCollision(this.getHandle(), aabb);
}
// Paper end - Collision API