From db988349caf1d1730cb0cac0d461ff87434a96c4 Mon Sep 17 00:00:00 2001 From: William278 Date: Mon, 27 Mar 2023 13:22:51 +0100 Subject: [PATCH 1/2] Add missing catch blocks for inbound local teleports --- .../huskhomes/listener/EventListener.java | 20 +++++++++++++++---- .../william278/huskhomes/user/OnlineUser.java | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java index 8dbcbd4c..c02ed224 100644 --- a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java +++ b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java @@ -96,19 +96,31 @@ public class EventListener { } }, 40L); } else { - teleporter.teleportLocally(spawn, plugin.getSettings().doAsynchronousTeleports()); + try { + teleporter.teleportLocally(spawn, plugin.getSettings().doAsynchronousTeleports()); + } catch (TeleportationException e) { + e.displayMessage(teleporter, plugin, new String[0]); + } } teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid"); }); } else { - teleporter.teleportLocally(bedPosition.get(), plugin.getSettings().doAsynchronousTeleports()); + try { + teleporter.teleportLocally(bedPosition.get(), plugin.getSettings().doAsynchronousTeleports()); + } catch (TeleportationException e) { + e.displayMessage(teleporter, plugin, new String[0]); + } } plugin.getDatabase().setCurrentTeleport(teleporter, null); plugin.getDatabase().setRespawnPosition(teleporter, bedPosition.orElse(null)); return; } - teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().doAsynchronousTeleports()); + try { + teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().doAsynchronousTeleports()); + } catch (TeleportationException e) { + e.displayMessage(teleporter, plugin, new String[0]); + } plugin.getDatabase().setCurrentTeleport(teleporter, null); teleport.displayTeleportingComplete(teleporter); }); @@ -187,7 +199,7 @@ public class EventListener { // Display the return by death via /back notification final boolean canReturnByDeath = plugin.getCommand(BackCommand.class) .map(command -> onlineUser.hasPermission(command.getPermission()) - && onlineUser.hasPermission(command.getPermission("death"))) + && onlineUser.hasPermission(command.getPermission("death"))) .orElse(false); if (plugin.getSettings().doBackCommandReturnByDeath() && canReturnByDeath) { plugin.getLocales().getLocale("return_by_death_notification") diff --git a/common/src/main/java/net/william278/huskhomes/user/OnlineUser.java b/common/src/main/java/net/william278/huskhomes/user/OnlineUser.java index ff616e43..be456189 100644 --- a/common/src/main/java/net/william278/huskhomes/user/OnlineUser.java +++ b/common/src/main/java/net/william278/huskhomes/user/OnlineUser.java @@ -12,6 +12,7 @@ import net.william278.huskhomes.config.Locales; import net.william278.huskhomes.position.Location; import net.william278.huskhomes.position.Position; import net.william278.huskhomes.teleport.Teleportable; +import net.william278.huskhomes.teleport.TeleportationException; import org.intellij.lang.annotations.Subst; import org.jetbrains.annotations.NotNull; @@ -159,7 +160,7 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs * @param location the {@link Location} to teleport the player to * @param asynchronous if the teleport should be asynchronous */ - public abstract void teleportLocally(@NotNull Location location, boolean asynchronous); + public abstract void teleportLocally(@NotNull Location location, boolean asynchronous) throws TeleportationException; /** * Send a plugin message to the user From f0ffed0d3b1a70014c4e620373a7d5198f3ea468 Mon Sep 17 00:00:00 2001 From: William278 Date: Mon, 27 Mar 2023 13:25:19 +0100 Subject: [PATCH 2/2] Add backup world resolution by environment name --- .../william278/huskhomes/util/BukkitAdapter.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/net/william278/huskhomes/util/BukkitAdapter.java b/bukkit/src/main/java/net/william278/huskhomes/util/BukkitAdapter.java index 9f8e6dac..8af76edf 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/util/BukkitAdapter.java +++ b/bukkit/src/main/java/net/william278/huskhomes/util/BukkitAdapter.java @@ -24,11 +24,22 @@ public final class BukkitAdapter { if (world == null) { world = Bukkit.getWorld(location.getWorld().getUuid()); } + if (world == null) { + world = Bukkit.getWorlds().stream() + .filter(w -> w.getEnvironment().name().equalsIgnoreCase(location.getWorld().getEnvironment().name())) + .findFirst().orElse(null); + } if (world == null) { return Optional.empty(); } - return Optional.of(new org.bukkit.Location(world, location.getX(), location.getY(), location.getZ(), - location.getYaw(), location.getPitch())); + return Optional.of(new org.bukkit.Location( + world, + location.getX(), + location.getY(), + location.getZ(), + location.getYaw(), + location.getPitch() + )); } /**