Skip to content

Commit 8f9f24f

Browse files
Add async teleportation
1 parent 5960d49 commit 8f9f24f

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'com.tcoded'
6-
version '0.2.2'
6+
version '0.2.3'
77

88
java {
99
sourceCompatibility = JavaVersion.VERSION_17

src/main/java/com/tcoded/folialib/impl/FoliaImplementation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,9 @@ public Player getPlayer(UUID uuid) {
214214
// This is thread-safe in folia
215215
return this.plugin.getServer().getPlayer(uuid);
216216
}
217+
218+
@Override
219+
public CompletableFuture<Boolean> teleportAsync(Player player, Location location) {
220+
return player.teleportAsync(location);
221+
}
217222
}

src/main/java/com/tcoded/folialib/impl/ServerImplementation.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,10 @@ public interface ServerImplementation {
200200
* @return Player instance
201201
*/
202202
Player getPlayer(UUID uuid);
203+
204+
/**
205+
* Teleport a player to a location async
206+
* @return Future when the teleport is completed or failed
207+
*/
208+
CompletableFuture<Boolean> teleportAsync(Player player, Location location);
203209
}

src/main/java/com/tcoded/folialib/impl/SpigotImplementation.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,20 @@ public Player getPlayer(UUID uuid) {
226226
// Fallback to null
227227
return null;
228228
}
229+
230+
@Override
231+
public CompletableFuture<Boolean> teleportAsync(Player player, Location location) {
232+
CompletableFuture<Boolean> future = new CompletableFuture<>();
233+
234+
this.runAtEntity(player, () -> {
235+
if (player.isValid() && player.isOnline()) {
236+
player.teleport(location);
237+
future.complete(true);
238+
} else {
239+
future.complete(false);
240+
}
241+
});
242+
243+
return future;
244+
}
229245
}

0 commit comments

Comments
 (0)