@@ -650,6 +650,7 @@ public Optional<Island> getProtectedIslandAt(@NonNull Location location) {
650
650
*/
651
651
private CompletableFuture <Location > getAsyncSafeHomeLocation (@ NonNull World world , @ NonNull User user ,
652
652
String homeName ) {
653
+ BentoBox .getInstance ().logDebug ("Getting safe home location for " + user .getName ());
653
654
CompletableFuture <Location > result = new CompletableFuture <>();
654
655
// Check if the world is a gamemode world and the player has an island
655
656
Location islandLoc = getIslandLocation (world , user .getUniqueId ());
@@ -669,10 +670,16 @@ private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World worl
669
670
Location namedHome = homeName .isBlank () ? null : getHomeLocation (world , user , name );
670
671
Location l = namedHome != null ? namedHome : defaultHome ;
671
672
if (l != null ) {
673
+ BentoBox .getInstance ().logDebug ("Loading the destination chunk asyc for " + user .getName ());
674
+ long time = System .currentTimeMillis ();
672
675
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 ());
673
679
// Check if it is safe
674
680
if (isSafeLocation (l )) {
675
681
result .complete (l );
682
+ BentoBox .getInstance ().logDebug ("Location is safe for " + user .getName ());
676
683
return ;
677
684
}
678
685
// To cover slabs, stairs and other half blocks, try one block above
@@ -681,51 +688,64 @@ private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World worl
681
688
// Adjust the home location accordingly
682
689
setHomeLocation (user , lPlusOne , name );
683
690
result .complete (lPlusOne );
691
+ BentoBox .getInstance ().logDebug ("Location is safe for " + user .getName ());
684
692
return ;
685
693
}
686
694
// Try island
687
695
tryIsland (result , islandLoc , user , name );
688
696
});
689
697
return result ;
690
698
}
699
+ BentoBox .getInstance ().logDebug ("No home locations found for " + user .getName ());
691
700
// Try island
692
701
tryIsland (result , islandLoc , user , name );
693
702
return result ;
694
703
}
695
704
696
705
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 ();
697
708
Util .getChunkAtAsync (islandLoc ).thenRun (() -> {
709
+ long duration = System .currentTimeMillis () - time ;
710
+ BentoBox .getInstance ().logDebug ("Island center chunk loaded for " + user .getName () + " in " + duration + "ms" );
698
711
World w = islandLoc .getWorld ();
699
712
if (isSafeLocation (islandLoc )) {
713
+ BentoBox .getInstance ().logDebug ("Location is safe for " + user .getName ());
700
714
setHomeLocation (user , islandLoc , name );
701
715
result .complete (islandLoc .clone ().add (new Vector (0.5D , 0 , 0.5D )));
702
716
return ;
703
717
} else {
718
+ BentoBox .getInstance ().logDebug ("Location is not safe for " + user .getName ());
704
719
// If these island locations are not safe, then we need to get creative
705
720
// Try the default location
706
721
Location dl = islandLoc .clone ().add (new Vector (0.5D , 5D , 2.5D ));
707
722
if (isSafeLocation (dl )) {
708
723
setHomeLocation (user , dl , name );
709
724
result .complete (dl );
725
+ BentoBox .getInstance ().logDebug ("Found that the default spot is safe " + user .getName ());
710
726
return ;
711
727
}
712
728
// Try just above the bedrock
713
729
dl = islandLoc .clone ().add (new Vector (0.5D , 5D , 0.5D ));
714
730
if (isSafeLocation (dl )) {
715
731
setHomeLocation (user , dl , name );
716
732
result .complete (dl );
733
+ BentoBox .getInstance ().logDebug ("Location above bedrock is safe for " + user .getName ());
717
734
return ;
718
735
}
736
+ BentoBox .getInstance ().logDebug ("Trying all locations up to max height above bedrock for " + user .getName ());
719
737
// Try all the way up to the sky
720
738
for (int y = islandLoc .getBlockY (); y < w .getMaxHeight (); y ++) {
721
739
dl = new Location (w , islandLoc .getX () + 0.5D , y , islandLoc .getZ () + 0.5D );
722
740
if (isSafeLocation (dl )) {
723
741
setHomeLocation (user , dl , name );
724
742
result .complete (dl );
743
+ BentoBox .getInstance ().logDebug ("Location is safe for " + user .getName ());
725
744
return ;
726
745
}
727
746
}
728
747
}
748
+ BentoBox .getInstance ().logDebug ("Nowhere is safe for " + user .getName ());
729
749
result .complete (null );
730
750
});
731
751
@@ -1051,21 +1071,27 @@ private CompletableFuture<Boolean> homeTeleportAsync(@NonNull World world, @NonN
1051
1071
user .sendMessage ("commands.island.go.teleport" );
1052
1072
goingHome .add (user .getUniqueId ());
1053
1073
readyPlayer (player );
1074
+ BentoBox .getInstance ().logDebug (user .getName () + " is going home" );
1054
1075
this .getAsyncSafeHomeLocation (world , user , name ).thenAccept (home -> {
1055
1076
Island island = getIsland (world , user );
1056
1077
if (home == null ) {
1078
+ BentoBox .getInstance ().logDebug ("Try to fix this teleport location and teleport the player if possible " + user .getName ());
1057
1079
// Try to fix this teleport location and teleport the player if possible
1058
1080
new SafeSpotTeleport .Builder (plugin ).entity (player ).island (island ).homeName (name )
1059
1081
.thenRun (() -> teleported (world , user , name , newIsland , island ))
1060
1082
.ifFail (() -> goingHome .remove (user .getUniqueId ())).buildFuture ().thenAccept (result ::complete );
1061
1083
return ;
1062
1084
}
1085
+ BentoBox .getInstance ().logDebug ("Teleporting " + player .getName () + " async" );
1086
+ long time = System .currentTimeMillis ();
1063
1087
PaperLib .teleportAsync (Objects .requireNonNull (player ), home ).thenAccept (b -> {
1064
1088
// Only run the commands if the player is successfully teleported
1065
1089
if (Boolean .TRUE .equals (b )) {
1090
+ BentoBox .getInstance ().logDebug ("Teleported " + player .getName () + " async - took " + (System .currentTimeMillis () - time ) + "ms" );
1066
1091
teleported (world , user , name , newIsland , island );
1067
1092
result .complete (true );
1068
1093
} else {
1094
+ BentoBox .getInstance ().logDebug ("Failed to teleport " + player .getName () + " async! - took " + (System .currentTimeMillis () - time ) + "ms" );
1069
1095
// Remove from mid-teleport set
1070
1096
goingHome .remove (user .getUniqueId ());
1071
1097
result .complete (false );
0 commit comments