55import com .mojang .brigadier .exceptions .CommandSyntaxException ;
66import me .drex .essentials .command .Command ;
77import me .drex .essentials .command .CommandProperties ;
8- import me .drex .essentials .config . Config ;
8+ import me .drex .essentials .command . util . CommandUtil ;
99import me .drex .essentials .config .ConfigManager ;
1010import me .drex .essentials .storage .DataStorage ;
1111import me .drex .essentials .storage .PlayerData ;
1212import me .drex .essentials .util .teleportation .Location ;
1313import me .drex .message .api .LocalizedMessage ;
1414import net .minecraft .commands .CommandBuildContext ;
1515import net .minecraft .commands .CommandSourceStack ;
16+ import net .minecraft .server .level .ServerLevel ;
1617
1718import static me .drex .message .api .LocalizedMessage .localized ;
1819
@@ -36,13 +37,22 @@ private int teleportBack(CommandContext<CommandSourceStack> ctx) throws CommandS
3637 return FAILURE ;
3738 }
3839 Location location = playerData .teleportLocations .pop ();
39- source .sendSystemMessage (
40- LocalizedMessage .builder ("fabric-essentials.commands.back" )
41- .addPlaceholders (location .placeholders ())
42- .build ()
43- );
44- location .teleport (target , ConfigManager .config ().teleportation .saveBackCommandLocation );
45- return SUCCESS ;
40+ ServerLevel level = location .getLevel (source .getServer ());
41+
42+ if (level != null ) {
43+ CommandUtil .asyncTeleport (source , level , location .chunkPos (), config ().teleportation .waitingPeriod ).whenCompleteAsync ((chunkAccess , throwable ) -> {
44+ if (chunkAccess == null ) return ;
45+ source .sendSystemMessage (
46+ LocalizedMessage .builder ("fabric-essentials.commands.back" )
47+ .addPlaceholders (location .placeholders ())
48+ .build ()
49+ );
50+ location .teleport (target , ConfigManager .config ().teleportation .saveBackCommandLocation );
51+ }, source .getServer ());
52+ return SUCCESS ;
53+ } else {
54+ throw WORLD_UNKNOWN .create ();
55+ }
4656 }
4757
4858}
0 commit comments