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

@@ -24,7 +24,6 @@ import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.user.OnlineUser;
import org.jetbrains.annotations.NotNull;
@@ -58,17 +57,11 @@ public abstract class Broker {
}
switch (message.getType()) {
case TELEPORT_TO_POSITION -> message.getPayload()
.getPosition().ifPresent(position -> {
try {
Teleport.builder(plugin)
.teleporter(receiver)
.target(position)
.toTeleport()
.execute();
} catch (TeleportationException e) {
e.displayMessage(plugin.getConsole());
}
});
.getPosition().ifPresent(position -> Teleport.builder(plugin)
.teleporter(receiver)
.target(position)
.toTeleport()
.complete());
case TELEPORT_TO_NETWORKED_POSITION -> Message.builder()
.type(Message.Type.TELEPORT_TO_POSITION)
.target(message.getSender())