FoliaLib icon indicating copy to clipboard operation
FoliaLib copied to clipboard

Support TeleportCause for function "teleportAsync"

Open TheFloodDragon opened this issue 2 years 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

Thank you for reminding me

I have made some changes and tried to comply with your request, please check.

And if you don't like merging two (clumsiness) commits, you can use the patch, it's no problem.

Support_TeleportCause_for_function__teleportAsync__(Fixed).patch

TheFloodDragon avatar Jan 05 '24 08:01 TheFloodDragon

It seems there is a replacement.

TheFloodDragon avatar Jun 30 '24 23:06 TheFloodDragon