refactor: Simplify teleport execution logic (#565)

* refactor: simplify teleport execution logic

* docs: document better way of executing a teleport

* fix: TimedTeleport should still handle internal errors

* fix: Wrong builder method calls

* fix: Typos

* fix: More typos

* fix: Cancel timed teleport on failed execute
This commit is contained in:
William authored and GitHub committed 2024-02-13 15:56:55 +00:00
1 parent 1723aa44fc
commit d79fcaacb6
17 files changed
+159 -209

No files matched your search

@@ -29,7 +29,6 @@ import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.random.RandomTeleportEngine;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportBuilder;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.SavedUser;
import net.william278.huskhomes.user.User;
@@ -773,18 +772,10 @@ public class BaseHuskHomesAPI {
throw new IllegalStateException("Random teleport engine returned an empty position");
}
final TeleportBuilder builder = Teleport.builder(plugin)
Teleport.builder(plugin)
.teleporter(user)
.target(position.get());
try {
if (timedTeleport) {
builder.toTimedTeleport().execute();
} else {
builder.toTeleport().execute();
}
} catch (TeleportationException e) {
e.displayMessage(user, rtpArgs);
}
.target(position.get())
.buildAndComplete(timedTeleport);
}).exceptionally(e -> {
throw new IllegalStateException("Random teleport engine threw an exception", e);
});