FoliaLib icon indicating copy to clipboard operation
FoliaLib copied to clipboard

Support TeleportCause for function "teleportAsync"

Open TheFloodDragon opened this issue 1 year ago • 1 comments

I have changed the method:

public CompletableFuture<Boolean> teleportAsync(Player player, Location location)

Now, it is:

public CompletableFuture<Boolean> teleportAsync(Entity entity, Location location, PlayerTeleportEvent.TeleportCause cause)

Why?

Because Player.teleport() is actually Entity.teleport()

And There is a argment named PlayerTeleportEvent.TeleportCause

Another Change

This part of code seems meaningless.

this.runAtEntity(player, (task) -> {
    if (player.isValid() && player.isOnline()) {
        player.teleport(location);
        future.complete(true);
    } else {
        future.complete(false);
    }
});

And it can be replaced with:

this.runAtEntity(entity, (task) -> future.complete(entity.teleport(location, cause)));

So I did it.

Hope to adopt, thank you, it's really useful and helpful to me

TheFloodDragon avatar Dec 31 '23 06:12 TheFloodDragon