Try using World#getChunkAtAsync() for the /spawn command

This commit is contained in:
Allink 2023-03-31 16:59:37 +01:00
parent ef47727bd0
commit 88fd25db5a
No known key found for this signature in database

View file

@ -2,7 +2,6 @@ package pw.kaboom.extras.commands;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
@ -31,18 +30,16 @@ public final class CommandSpawn implements CommandExecutor {
final World defaultWorld = Bukkit.getWorld("world");
final World world = (defaultWorld == null) ? Bukkit.getWorlds().get(0) : defaultWorld;
final Location spawnLocation = world.getSpawnLocation();
final Main plugin = JavaPlugin.getPlugin(Main.class);
PlatformScheduler.executeOnGlobalRegion(plugin, () -> {
final Chunk chunk = spawnLocation.getChunk();
world.getChunkAtAsync(spawnLocation).thenAccept(chunk -> {
final Main plugin = JavaPlugin.getPlugin(Main.class);
final Location highestSpawnLocation = world.getHighestBlockAt(spawnLocation)
.getLocation()
.add(0, 1, 0);
PlatformScheduler.executeOnChunk(plugin, chunk, () -> {
final Location safeSpawnLocation = world.getHighestBlockAt(spawnLocation)
.getLocation()
.add(0, 20, 0);
player.teleportAsync(safeSpawnLocation);
player.sendMessage(Component
.text("Successfully moved to spawn"));
PlatformScheduler.executeOnEntity(plugin, player, () -> {
player.teleportAsync(highestSpawnLocation);
player.sendMessage(Component.text("Successfully moved to spawn"));
});
});