Skip to content

Commit 1085332

Browse files
authored
Merge pull request #2525 from BentoBoxWorld/2524_is_teleport_command_delay
Improve teleporting #2524 - this commit has debug.
2 parents 81fb17d + b949727 commit 1085332

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/main/java/world/bentobox/bentobox/api/commands/island/IslandGoCommand.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public boolean canExecute(User user, String label, List<String> args) {
3737
// Check if mid-teleport
3838
if (getIslands().isGoingHome(user)) {
3939
// Tell them again that it's in progress
40-
user.sendMessage("commands.island.go.teleport");
40+
user.sendMessage("commands.island.go.in-progress");
4141
return false;
4242
}
4343
List<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
@@ -76,7 +76,15 @@ public boolean execute(User user, String label, List<String> args) {
7676
getIslands().setPrimaryIsland(user.getUniqueId(), info.island);
7777
if (!info.islandName) {
7878
this.delayCommand(user, () -> getIslands().homeTeleportAsync(getWorld(), user.getPlayer(), name)
79-
.thenAccept((r) -> getIslands().setPrimaryIsland(user.getUniqueId(), info.island)));
79+
.thenAccept((r) -> {
80+
if (r.booleanValue()) {
81+
// Success
82+
getIslands().setPrimaryIsland(user.getUniqueId(), info.island);
83+
} else {
84+
user.sendMessage("commands.island.go.failure");
85+
getPlugin().logError(user.getName() + " could not teleport to their island - async teleport issue");
86+
}
87+
}));
8088
return true;
8189
}
8290
}

src/main/java/world/bentobox/bentobox/managers/IslandsManager.java

+26
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ public Optional<Island> getProtectedIslandAt(@NonNull Location location) {
650650
*/
651651
private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World world, @NonNull User user,
652652
String homeName) {
653+
BentoBox.getInstance().logDebug("Getting safe home location for " + user.getName());
653654
CompletableFuture<Location> result = new CompletableFuture<>();
654655
// Check if the world is a gamemode world and the player has an island
655656
Location islandLoc = getIslandLocation(world, user.getUniqueId());
@@ -669,10 +670,16 @@ private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World worl
669670
Location namedHome = homeName.isBlank() ? null : getHomeLocation(world, user, name);
670671
Location l = namedHome != null ? namedHome : defaultHome;
671672
if (l != null) {
673+
BentoBox.getInstance().logDebug("Loading the destination chunk asyc for " + user.getName());
674+
long time = System.currentTimeMillis();
672675
Util.getChunkAtAsync(l).thenRun(() -> {
676+
long duration = System.currentTimeMillis() - time;
677+
BentoBox.getInstance().logDebug("Chunk loaded asyc for " + user.getName() + " in " + duration + "ms");
678+
BentoBox.getInstance().logDebug("Checking if the location is safe for " + user.getName());
673679
// Check if it is safe
674680
if (isSafeLocation(l)) {
675681
result.complete(l);
682+
BentoBox.getInstance().logDebug("Location is safe for " + user.getName());
676683
return;
677684
}
678685
// To cover slabs, stairs and other half blocks, try one block above
@@ -681,51 +688,64 @@ private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World worl
681688
// Adjust the home location accordingly
682689
setHomeLocation(user, lPlusOne, name);
683690
result.complete(lPlusOne);
691+
BentoBox.getInstance().logDebug("Location is safe for " + user.getName());
684692
return;
685693
}
686694
// Try island
687695
tryIsland(result, islandLoc, user, name);
688696
});
689697
return result;
690698
}
699+
BentoBox.getInstance().logDebug("No home locations found for " + user.getName());
691700
// Try island
692701
tryIsland(result, islandLoc, user, name);
693702
return result;
694703
}
695704

696705
private void tryIsland(CompletableFuture<Location> result, Location islandLoc, @NonNull User user, String name) {
706+
BentoBox.getInstance().logDebug(user.getName() + ": we need to try other locations on the island. Load the island center chunk async...");
707+
long time = System.currentTimeMillis();
697708
Util.getChunkAtAsync(islandLoc).thenRun(() -> {
709+
long duration = System.currentTimeMillis() - time;
710+
BentoBox.getInstance().logDebug("Island center chunk loaded for " + user.getName() + " in " + duration + "ms");
698711
World w = islandLoc.getWorld();
699712
if (isSafeLocation(islandLoc)) {
713+
BentoBox.getInstance().logDebug("Location is safe for " + user.getName());
700714
setHomeLocation(user, islandLoc, name);
701715
result.complete(islandLoc.clone().add(new Vector(0.5D, 0, 0.5D)));
702716
return;
703717
} else {
718+
BentoBox.getInstance().logDebug("Location is not safe for " + user.getName());
704719
// If these island locations are not safe, then we need to get creative
705720
// Try the default location
706721
Location dl = islandLoc.clone().add(new Vector(0.5D, 5D, 2.5D));
707722
if (isSafeLocation(dl)) {
708723
setHomeLocation(user, dl, name);
709724
result.complete(dl);
725+
BentoBox.getInstance().logDebug("Found that the default spot is safe " + user.getName());
710726
return;
711727
}
712728
// Try just above the bedrock
713729
dl = islandLoc.clone().add(new Vector(0.5D, 5D, 0.5D));
714730
if (isSafeLocation(dl)) {
715731
setHomeLocation(user, dl, name);
716732
result.complete(dl);
733+
BentoBox.getInstance().logDebug("Location above bedrock is safe for " + user.getName());
717734
return;
718735
}
736+
BentoBox.getInstance().logDebug("Trying all locations up to max height above bedrock for " + user.getName());
719737
// Try all the way up to the sky
720738
for (int y = islandLoc.getBlockY(); y < w.getMaxHeight(); y++) {
721739
dl = new Location(w, islandLoc.getX() + 0.5D, y, islandLoc.getZ() + 0.5D);
722740
if (isSafeLocation(dl)) {
723741
setHomeLocation(user, dl, name);
724742
result.complete(dl);
743+
BentoBox.getInstance().logDebug("Location is safe for " + user.getName());
725744
return;
726745
}
727746
}
728747
}
748+
BentoBox.getInstance().logDebug("Nowhere is safe for " + user.getName());
729749
result.complete(null);
730750
});
731751

@@ -1051,21 +1071,27 @@ private CompletableFuture<Boolean> homeTeleportAsync(@NonNull World world, @NonN
10511071
user.sendMessage("commands.island.go.teleport");
10521072
goingHome.add(user.getUniqueId());
10531073
readyPlayer(player);
1074+
BentoBox.getInstance().logDebug(user.getName() + " is going home");
10541075
this.getAsyncSafeHomeLocation(world, user, name).thenAccept(home -> {
10551076
Island island = getIsland(world, user);
10561077
if (home == null) {
1078+
BentoBox.getInstance().logDebug("Try to fix this teleport location and teleport the player if possible " + user.getName());
10571079
// Try to fix this teleport location and teleport the player if possible
10581080
new SafeSpotTeleport.Builder(plugin).entity(player).island(island).homeName(name)
10591081
.thenRun(() -> teleported(world, user, name, newIsland, island))
10601082
.ifFail(() -> goingHome.remove(user.getUniqueId())).buildFuture().thenAccept(result::complete);
10611083
return;
10621084
}
1085+
BentoBox.getInstance().logDebug("Teleporting " + player.getName() + " async");
1086+
long time = System.currentTimeMillis();
10631087
PaperLib.teleportAsync(Objects.requireNonNull(player), home).thenAccept(b -> {
10641088
// Only run the commands if the player is successfully teleported
10651089
if (Boolean.TRUE.equals(b)) {
1090+
BentoBox.getInstance().logDebug("Teleported " + player.getName() + " async - took " + (System.currentTimeMillis() - time) + "ms");
10661091
teleported(world, user, name, newIsland, island);
10671092
result.complete(true);
10681093
} else {
1094+
BentoBox.getInstance().logDebug("Failed to teleport " + player.getName() + " async! - took " + (System.currentTimeMillis() - time) + "ms");
10691095
// Remove from mid-teleport set
10701096
goingHome.remove(user.getUniqueId());
10711097
result.complete(false);

src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java

+4
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ void teleportEntity(final Location loc) {
279279
task.cancel();
280280
// Return to main thread and teleport the player
281281
Bukkit.getScheduler().runTask(plugin, () -> {
282+
BentoBox.getInstance().logDebug("Home number = " + homeNumber + " Home name = '" + homeName + "'");
283+
plugin.getIslands().getIslandAt(loc).ifPresent(is ->
284+
plugin.getIslands().getHomeLocations(is).forEach((k,v) -> BentoBox.getInstance().logDebug("'" + k + "' => " + v)));
282285
if (!portal && entity instanceof Player && (homeNumber > 0 || !homeName.isEmpty())) {
286+
BentoBox.getInstance().logDebug("Setting home");
283287
// Set home if so marked
284288
plugin.getIslands().setHomeLocation(User.getInstance(entity), loc, homeName);
285289
}

src/main/resources/locales/en-US.yml

+2
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@ commands:
551551
parameters: '[home name]'
552552
description: teleport you to your island
553553
teleport: '&a Teleporting you to your island.'
554+
in-progress: '&a Teleporting in progress, please wait...'
554555
teleported: '&a Teleported you to home &e [number].'
556+
failure: '&c Teleporting failed for some reason. Please try again later.'
555557
unknown-home: '&c Unknown home name!'
556558
help:
557559
description: the main island command

0 commit comments

Comments
 (0)