Skip to content

Commit ae979da

Browse files
authored
fix: recommend teleportAsync usage over teleport (#396)
1 parent 36f1f88 commit ae979da

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

docs/paper/dev/api/entity-api/entity-teleport.mdx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ Entities can be instantaneously teleported to specific positions, synchronously
99
<Javadoc name={"org.bukkit.entity.Entity#teleport(org.bukkit.Location)"}>`teleport`</Javadoc> and
1010
<Javadoc name={"org.bukkit.entity.Entity#teleportAsync(org.bukkit.Location)"}>`teleportAsync`</Javadoc> API.
1111

12+
:::tip[Performance]
13+
14+
If you expect to teleport into unloaded chunks, it is recommended to use the `teleportAsync` API,
15+
as it avoids doing synchronous chunk loads, which put a lot of stress on the server's main thread -
16+
hurting overall performance.
17+
18+
:::
19+
1220
```java
13-
entity.teleport(location); // teleports the entity synchronously
21+
entity.teleport(location); // loads chunks synchronously and teleports the entity
1422

15-
entity.teleportAsync(location).thenAccept(success -> { // teleports the entity asynchronously
23+
entity.teleportAsync(location).thenAccept(success -> { // loads chunks asynchronously and teleports the entity
1624
// this code is ran when the teleport completes
1725
// the Future is completed on the main thread, so it is safe to use the API here
1826

@@ -22,6 +30,13 @@ entity.teleportAsync(location).thenAccept(success -> { // teleports the entity a
2230
});
2331
```
2432

33+
:::danger
34+
35+
You should **NEVER** call `.get()`/`.join()` on the `teleportAsync` `Future` on the main thread,
36+
as it **WILL** deadlock your server, if the chunk you're teleporting into is not loaded.
37+
38+
:::
39+
2540
## Look at
2641

2742
The <Javadoc name={"org.bukkit.entity.Player#lookAt(io.papermc.paper.math.Position,io.papermc.paper.entity.LookAnchor)"}>`lookAt`</Javadoc>

0 commit comments

Comments
 (0)