11package pw .kaboom .extras .commands ;
22
33import net .kyori .adventure .text .Component ;
4- import org .bukkit .Bukkit ;
5- import org .bukkit .Location ;
6- import org .bukkit .World ;
7- import org .bukkit .block .Block ;
8- import org .bukkit .block .BlockFace ;
94import org .bukkit .command .Command ;
105import org .bukkit .command .CommandExecutor ;
116import org .bukkit .command .CommandSender ;
127import org .bukkit .entity .Player ;
8+ import org .bukkit .event .player .PlayerTeleportEvent ;
9+ import pw .kaboom .extras .util .Utility ;
1310
1411import javax .annotation .Nonnull ;
1512
@@ -24,23 +21,7 @@ public boolean onCommand(final @Nonnull CommandSender sender,
2421 return true ;
2522 }
2623
27- final World defaultWorld = Bukkit .getWorld ("world" );
28- final World world = (defaultWorld == null ) ? Bukkit .getWorlds ().get (0 ) : defaultWorld ;
29- final Location spawnLocation = world .getSpawnLocation ();
30- final int maxWorldHeight = 256 ;
31-
32- for (double y = spawnLocation .getY (); y <= maxWorldHeight ; y ++) {
33- final Location yLocation = new Location (world , spawnLocation .getX (), y ,
34- spawnLocation .getZ ());
35- final Block coordBlock = world .getBlockAt (yLocation );
36-
37- if (!coordBlock .getType ().isSolid ()
38- && !coordBlock .getRelative (BlockFace .UP ).getType ().isSolid ()) {
39- player .teleportAsync (yLocation );
40- break ;
41- }
42- }
43-
24+ Utility .teleportToSpawn (player , PlayerTeleportEvent .TeleportCause .COMMAND );
4425 player .sendMessage (Component
4526 .text ("Successfully moved to spawn" ));
4627 return true ;
0 commit comments