mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-25 12:15:12 +01:00
Improve teleporting #2524 - this commit has debug.
This commit is contained in:
parent
83b7c66c4f
commit
aa19319d58
@ -37,7 +37,7 @@ public class IslandGoCommand extends DelayedTeleportCommand {
|
|||||||
// Check if mid-teleport
|
// Check if mid-teleport
|
||||||
if (getIslands().isGoingHome(user)) {
|
if (getIslands().isGoingHome(user)) {
|
||||||
// Tell them again that it's in progress
|
// Tell them again that it's in progress
|
||||||
user.sendMessage("commands.island.go.teleport");
|
user.sendMessage("commands.island.go.in-progress");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
|
List<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
|
||||||
@ -76,7 +76,15 @@ public class IslandGoCommand extends DelayedTeleportCommand {
|
|||||||
getIslands().setPrimaryIsland(user.getUniqueId(), info.island);
|
getIslands().setPrimaryIsland(user.getUniqueId(), info.island);
|
||||||
if (!info.islandName) {
|
if (!info.islandName) {
|
||||||
this.delayCommand(user, () -> getIslands().homeTeleportAsync(getWorld(), user.getPlayer(), name)
|
this.delayCommand(user, () -> getIslands().homeTeleportAsync(getWorld(), user.getPlayer(), name)
|
||||||
.thenAccept((r) -> getIslands().setPrimaryIsland(user.getUniqueId(), info.island)));
|
.thenAccept((r) -> {
|
||||||
|
if (r.booleanValue()) {
|
||||||
|
// Success
|
||||||
|
getIslands().setPrimaryIsland(user.getUniqueId(), info.island);
|
||||||
|
} else {
|
||||||
|
user.sendMessage("commands.island.go.failure");
|
||||||
|
getPlugin().logError(user.getName() + " could not teleprot to their island - async teleport issue");
|
||||||
|
}
|
||||||
|
}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -650,6 +650,7 @@ public class IslandsManager {
|
|||||||
*/
|
*/
|
||||||
private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World world, @NonNull User user,
|
private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World world, @NonNull User user,
|
||||||
String homeName) {
|
String homeName) {
|
||||||
|
BentoBox.getInstance().logDebug("Getting safe home location for " + user.getName());
|
||||||
CompletableFuture<Location> result = new CompletableFuture<>();
|
CompletableFuture<Location> result = new CompletableFuture<>();
|
||||||
// Check if the world is a gamemode world and the player has an island
|
// Check if the world is a gamemode world and the player has an island
|
||||||
Location islandLoc = getIslandLocation(world, user.getUniqueId());
|
Location islandLoc = getIslandLocation(world, user.getUniqueId());
|
||||||
@ -669,10 +670,16 @@ public class IslandsManager {
|
|||||||
Location namedHome = homeName.isBlank() ? null : getHomeLocation(world, user, name);
|
Location namedHome = homeName.isBlank() ? null : getHomeLocation(world, user, name);
|
||||||
Location l = namedHome != null ? namedHome : defaultHome;
|
Location l = namedHome != null ? namedHome : defaultHome;
|
||||||
if (l != null) {
|
if (l != null) {
|
||||||
|
BentoBox.getInstance().logDebug("Loading the destination chunk asyc for " + user.getName());
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
Util.getChunkAtAsync(l).thenRun(() -> {
|
Util.getChunkAtAsync(l).thenRun(() -> {
|
||||||
|
long duration = System.currentTimeMillis() - time;
|
||||||
|
BentoBox.getInstance().logDebug("Chunk loaded asyc for " + user.getName() + " in " + duration + "ms");
|
||||||
|
BentoBox.getInstance().logDebug("Checking if the location is safe for " + user.getName());
|
||||||
// Check if it is safe
|
// Check if it is safe
|
||||||
if (isSafeLocation(l)) {
|
if (isSafeLocation(l)) {
|
||||||
result.complete(l);
|
result.complete(l);
|
||||||
|
BentoBox.getInstance().logDebug("Location is safe for " + user.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// To cover slabs, stairs and other half blocks, try one block above
|
// To cover slabs, stairs and other half blocks, try one block above
|
||||||
@ -681,6 +688,7 @@ public class IslandsManager {
|
|||||||
// Adjust the home location accordingly
|
// Adjust the home location accordingly
|
||||||
setHomeLocation(user, lPlusOne, name);
|
setHomeLocation(user, lPlusOne, name);
|
||||||
result.complete(lPlusOne);
|
result.complete(lPlusOne);
|
||||||
|
BentoBox.getInstance().logDebug("Location is safe for " + user.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Try island
|
// Try island
|
||||||
@ -688,25 +696,33 @@ public class IslandsManager {
|
|||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
BentoBox.getInstance().logDebug("No home locations found for " + user.getName());
|
||||||
// Try island
|
// Try island
|
||||||
tryIsland(result, islandLoc, user, name);
|
tryIsland(result, islandLoc, user, name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryIsland(CompletableFuture<Location> result, Location islandLoc, @NonNull User user, String name) {
|
private void tryIsland(CompletableFuture<Location> result, Location islandLoc, @NonNull User user, String name) {
|
||||||
|
BentoBox.getInstance().logDebug(user.getName() + ": we need to try other locations on the island. Load the island center chunk async...");
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
Util.getChunkAtAsync(islandLoc).thenRun(() -> {
|
Util.getChunkAtAsync(islandLoc).thenRun(() -> {
|
||||||
|
long duration = System.currentTimeMillis() - time;
|
||||||
|
BentoBox.getInstance().logDebug("Island center chunk loaded for " + user.getName() + " in " + duration + "ms");
|
||||||
World w = islandLoc.getWorld();
|
World w = islandLoc.getWorld();
|
||||||
if (isSafeLocation(islandLoc)) {
|
if (isSafeLocation(islandLoc)) {
|
||||||
|
BentoBox.getInstance().logDebug("Location is safe for " + user.getName());
|
||||||
setHomeLocation(user, islandLoc, name);
|
setHomeLocation(user, islandLoc, name);
|
||||||
result.complete(islandLoc.clone().add(new Vector(0.5D, 0, 0.5D)));
|
result.complete(islandLoc.clone().add(new Vector(0.5D, 0, 0.5D)));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
BentoBox.getInstance().logDebug("Location is not safe for " + user.getName());
|
||||||
// If these island locations are not safe, then we need to get creative
|
// If these island locations are not safe, then we need to get creative
|
||||||
// Try the default location
|
// Try the default location
|
||||||
Location dl = islandLoc.clone().add(new Vector(0.5D, 5D, 2.5D));
|
Location dl = islandLoc.clone().add(new Vector(0.5D, 5D, 2.5D));
|
||||||
if (isSafeLocation(dl)) {
|
if (isSafeLocation(dl)) {
|
||||||
setHomeLocation(user, dl, name);
|
setHomeLocation(user, dl, name);
|
||||||
result.complete(dl);
|
result.complete(dl);
|
||||||
|
BentoBox.getInstance().logDebug("Found that the default spot is safe " + user.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Try just above the bedrock
|
// Try just above the bedrock
|
||||||
@ -714,18 +730,22 @@ public class IslandsManager {
|
|||||||
if (isSafeLocation(dl)) {
|
if (isSafeLocation(dl)) {
|
||||||
setHomeLocation(user, dl, name);
|
setHomeLocation(user, dl, name);
|
||||||
result.complete(dl);
|
result.complete(dl);
|
||||||
|
BentoBox.getInstance().logDebug("Location above bedrock is safe for " + user.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BentoBox.getInstance().logDebug("Trying all locations up to max height above bedrock for " + user.getName());
|
||||||
// Try all the way up to the sky
|
// Try all the way up to the sky
|
||||||
for (int y = islandLoc.getBlockY(); y < w.getMaxHeight(); y++) {
|
for (int y = islandLoc.getBlockY(); y < w.getMaxHeight(); y++) {
|
||||||
dl = new Location(w, islandLoc.getX() + 0.5D, y, islandLoc.getZ() + 0.5D);
|
dl = new Location(w, islandLoc.getX() + 0.5D, y, islandLoc.getZ() + 0.5D);
|
||||||
if (isSafeLocation(dl)) {
|
if (isSafeLocation(dl)) {
|
||||||
setHomeLocation(user, dl, name);
|
setHomeLocation(user, dl, name);
|
||||||
result.complete(dl);
|
result.complete(dl);
|
||||||
|
BentoBox.getInstance().logDebug("Location is safe for " + user.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BentoBox.getInstance().logDebug("Nowhere is safe for " + user.getName());
|
||||||
result.complete(null);
|
result.complete(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1051,21 +1071,27 @@ public class IslandsManager {
|
|||||||
user.sendMessage("commands.island.go.teleport");
|
user.sendMessage("commands.island.go.teleport");
|
||||||
goingHome.add(user.getUniqueId());
|
goingHome.add(user.getUniqueId());
|
||||||
readyPlayer(player);
|
readyPlayer(player);
|
||||||
|
BentoBox.getInstance().logDebug(user.getName() + " is going home");
|
||||||
this.getAsyncSafeHomeLocation(world, user, name).thenAccept(home -> {
|
this.getAsyncSafeHomeLocation(world, user, name).thenAccept(home -> {
|
||||||
Island island = getIsland(world, user);
|
Island island = getIsland(world, user);
|
||||||
if (home == null) {
|
if (home == null) {
|
||||||
|
BentoBox.getInstance().logDebug("Try to fix this teleport location and teleport the player if possible " + user.getName());
|
||||||
// Try to fix this teleport location and teleport the player if possible
|
// Try to fix this teleport location and teleport the player if possible
|
||||||
new SafeSpotTeleport.Builder(plugin).entity(player).island(island).homeName(name)
|
new SafeSpotTeleport.Builder(plugin).entity(player).island(island).homeName(name)
|
||||||
.thenRun(() -> teleported(world, user, name, newIsland, island))
|
.thenRun(() -> teleported(world, user, name, newIsland, island))
|
||||||
.ifFail(() -> goingHome.remove(user.getUniqueId())).buildFuture().thenAccept(result::complete);
|
.ifFail(() -> goingHome.remove(user.getUniqueId())).buildFuture().thenAccept(result::complete);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BentoBox.getInstance().logDebug("Teleporting " + player.getName() + " async");
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
PaperLib.teleportAsync(Objects.requireNonNull(player), home).thenAccept(b -> {
|
PaperLib.teleportAsync(Objects.requireNonNull(player), home).thenAccept(b -> {
|
||||||
// Only run the commands if the player is successfully teleported
|
// Only run the commands if the player is successfully teleported
|
||||||
if (Boolean.TRUE.equals(b)) {
|
if (Boolean.TRUE.equals(b)) {
|
||||||
|
BentoBox.getInstance().logDebug("Teleported " + player.getName() + " async - took " + (System.currentTimeMillis() - time) + "ms");
|
||||||
teleported(world, user, name, newIsland, island);
|
teleported(world, user, name, newIsland, island);
|
||||||
result.complete(true);
|
result.complete(true);
|
||||||
} else {
|
} else {
|
||||||
|
BentoBox.getInstance().logDebug("Failed to teleport " + player.getName() + " async! - took " + (System.currentTimeMillis() - time) + "ms");
|
||||||
// Remove from mid-teleport set
|
// Remove from mid-teleport set
|
||||||
goingHome.remove(user.getUniqueId());
|
goingHome.remove(user.getUniqueId());
|
||||||
result.complete(false);
|
result.complete(false);
|
||||||
|
@ -279,7 +279,11 @@ public class SafeSpotTeleport {
|
|||||||
task.cancel();
|
task.cancel();
|
||||||
// Return to main thread and teleport the player
|
// Return to main thread and teleport the player
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
BentoBox.getInstance().logDebug("Home number = " + homeNumber + " Home name = '" + homeName + "'");
|
||||||
|
plugin.getIslands().getIslandAt(loc).ifPresent(is ->
|
||||||
|
plugin.getIslands().getHomeLocations(is).forEach((k,v) -> BentoBox.getInstance().logDebug("'" + k + "' => " + v)));
|
||||||
if (!portal && entity instanceof Player && (homeNumber > 0 || !homeName.isEmpty())) {
|
if (!portal && entity instanceof Player && (homeNumber > 0 || !homeName.isEmpty())) {
|
||||||
|
BentoBox.getInstance().logDebug("Setting home");
|
||||||
// Set home if so marked
|
// Set home if so marked
|
||||||
plugin.getIslands().setHomeLocation(User.getInstance(entity), loc, homeName);
|
plugin.getIslands().setHomeLocation(User.getInstance(entity), loc, homeName);
|
||||||
}
|
}
|
||||||
|
@ -548,7 +548,9 @@ commands:
|
|||||||
parameters: '[home name]'
|
parameters: '[home name]'
|
||||||
description: teleport you to your island
|
description: teleport you to your island
|
||||||
teleport: '&a Teleporting you to your island.'
|
teleport: '&a Teleporting you to your island.'
|
||||||
|
in-progress: '&a Teleporting in progress, please wait...'
|
||||||
teleported: '&a Teleported you to home &e [number].'
|
teleported: '&a Teleported you to home &e [number].'
|
||||||
|
failure: '&c Teleporting failed for some reason. Please try again later.'
|
||||||
unknown-home: '&c Unknown home name!'
|
unknown-home: '&c Unknown home name!'
|
||||||
help:
|
help:
|
||||||
description: the main island command
|
description: the main island command
|
||||||
|
Loading…
Reference in New Issue
Block a user