diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java index ac13ddbb0..4b97192f3 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java @@ -1101,6 +1101,7 @@ public class IslandsManager { .island(island) .homeName(name) .thenRun(() -> teleported(world, user, name, newIsland, island)) + .ifFail(() -> goingHome.remove(user.getUniqueId())) .buildFuture() .thenAccept(result::complete); return; @@ -1115,9 +1116,10 @@ public class IslandsManager { teleported(world, user, name, newIsland, island); result.complete(true); } else { + // Remove from mid-teleport set + goingHome.remove(user.getUniqueId()); result.complete(false); } - }); }); return result; @@ -1135,6 +1137,8 @@ public class IslandsManager { if (!name.isEmpty()) { user.sendMessage("commands.island.go.teleported", TextVariables.NUMBER, name); } + // Remove from mid-teleport set + goingHome.remove(user.getUniqueId()); // If this is a new island, then run commands and do resets if (newIsland) { // Fire event @@ -1178,10 +1182,7 @@ public class IslandsManager { // Set the game mode user.setGameMode(plugin.getIWM().getDefaultGameMode(world)); - } - // Remove from mid-teleport set - goingHome.remove(user.getUniqueId()); } /** diff --git a/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java b/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java index 9879cb469..fedad9a52 100644 --- a/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java +++ b/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java @@ -49,6 +49,7 @@ public class SafeSpotTeleport { private final BentoBox plugin; private List> chunksToScan; private final Runnable runnable; + private final Runnable failRunnable; private final CompletableFuture result; private final String homeName; private final int maxHeight; @@ -65,6 +66,7 @@ public class SafeSpotTeleport { this.homeNumber = builder.getHomeNumber(); this.homeName = builder.getHomeName(); this.runnable = builder.getRunnable(); + this.failRunnable = builder.getFailRunnable(); this.result = builder.getResult(); this.maxHeight = location.getWorld().getMaxHeight() - 20; // Try to go @@ -151,9 +153,15 @@ public class SafeSpotTeleport { makeAndTelport(Material.COBBLESTONE); } } + if (failRunnable != null) { + Bukkit.getScheduler().runTask(plugin, failRunnable); + } result.complete(false); }); } else { + if (failRunnable != null) { + Bukkit.getScheduler().runTask(plugin, failRunnable); + } result.complete(false); } } @@ -300,6 +308,7 @@ public class SafeSpotTeleport { private String failureMessage = ""; private Location location; private Runnable runnable; + private Runnable failRunnable; private final CompletableFuture result = new CompletableFuture<>(); public Builder(BentoBox plugin) { @@ -423,6 +432,16 @@ public class SafeSpotTeleport { return this; } + /** + * The task to run if the player is not safely teleported + * @param runnable - task + * @return Builder + * @since 1.18.0 + */ + public Builder ifFail(Runnable rannable) { + this.failRunnable = runnable; + return this; + } /** * @return the plugin */ @@ -487,6 +506,13 @@ public class SafeSpotTeleport { return result; } + /** + * @return the failRunnable + */ + public Runnable getFailRunnable() { + return failRunnable; + } + } }