From ed1357638cf873b9bd2098b4dd58ac13f49bae82 Mon Sep 17 00:00:00 2001 From: William Date: Sun, 26 Mar 2023 14:08:24 +0100 Subject: [PATCH] Resolve executor during builder when not set --- .../huskhomes/teleport/TeleportBuilder.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java b/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java index 4be058c7..441cb674 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java @@ -27,7 +27,7 @@ public class TeleportBuilder { } @NotNull - public TimedTeleport toTimedTeleport() throws IllegalStateException { + public TimedTeleport toTimedTeleport() throws TeleportationException, IllegalStateException { validateTeleport(); if (!(teleporter instanceof OnlineUser onlineTeleporter)) { throw new IllegalStateException("Teleporter must be an OnlineUser for timed teleportation"); @@ -36,19 +36,20 @@ public class TeleportBuilder { plugin.getSettings().getTeleportWarmupTime(), updateLastPosition, economyActions, plugin); } - private void validateTeleport() throws IllegalStateException { + private void validateTeleport() throws TeleportationException { if (teleporter == null) { - throw new IllegalStateException("Teleporter must be set"); + throw new TeleportationException(TeleportationException.Type.TELEPORTER_NOT_FOUND); } if (executor == null) { if (teleporter instanceof OnlineUser onlineUser) { executor = onlineUser; } else { - throw new IllegalStateException("Executor must be set if teleporter is not an OnlineUser"); + executor = ((Username) teleporter).findLocally(plugin) + .orElseThrow(() -> new TeleportationException(TeleportationException.Type.TELEPORTER_NOT_FOUND)); } } if (target == null) { - throw new IllegalStateException("Target must be set"); + throw new TeleportationException(TeleportationException.Type.TARGET_NOT_FOUND); } }