Clear the going home flag for edge cases

There were a few potential times when the flag may not have been
cleared. These were mostly teleport failure scenarios. Hopefully, this
is all of them.

https://github.com/BentoBoxWorld/BentoBox/issues/1864
This commit is contained in:
tastybento 2021-10-16 20:44:18 -07:00
parent 731d902d98
commit 930433b64b
2 changed files with 31 additions and 4 deletions

View File

@ -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());
}
/**

View File

@ -49,6 +49,7 @@ public class SafeSpotTeleport {
private final BentoBox plugin;
private List<Pair<Integer, Integer>> chunksToScan;
private final Runnable runnable;
private final Runnable failRunnable;
private final CompletableFuture<Boolean> 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<Boolean> 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;
}
}
}