mirror of
https://github.com/kaboomserver/extras.git
synced 2025-02-11 20:00:43 +00:00
Try using World#getChunkAtAsync() for the /spawn command
This commit is contained in:
parent
ef47727bd0
commit
88fd25db5a
1 changed files with 8 additions and 11 deletions
|
@ -2,7 +2,6 @@ package pw.kaboom.extras.commands;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -31,18 +30,16 @@ public final class CommandSpawn implements CommandExecutor {
|
||||||
final World defaultWorld = Bukkit.getWorld("world");
|
final World defaultWorld = Bukkit.getWorld("world");
|
||||||
final World world = (defaultWorld == null) ? Bukkit.getWorlds().get(0) : defaultWorld;
|
final World world = (defaultWorld == null) ? Bukkit.getWorlds().get(0) : defaultWorld;
|
||||||
final Location spawnLocation = world.getSpawnLocation();
|
final Location spawnLocation = world.getSpawnLocation();
|
||||||
final Main plugin = JavaPlugin.getPlugin(Main.class);
|
|
||||||
|
|
||||||
PlatformScheduler.executeOnGlobalRegion(plugin, () -> {
|
world.getChunkAtAsync(spawnLocation).thenAccept(chunk -> {
|
||||||
final Chunk chunk = spawnLocation.getChunk();
|
final Main plugin = JavaPlugin.getPlugin(Main.class);
|
||||||
|
final Location highestSpawnLocation = world.getHighestBlockAt(spawnLocation)
|
||||||
|
.getLocation()
|
||||||
|
.add(0, 1, 0);
|
||||||
|
|
||||||
PlatformScheduler.executeOnChunk(plugin, chunk, () -> {
|
PlatformScheduler.executeOnEntity(plugin, player, () -> {
|
||||||
final Location safeSpawnLocation = world.getHighestBlockAt(spawnLocation)
|
player.teleportAsync(highestSpawnLocation);
|
||||||
.getLocation()
|
player.sendMessage(Component.text("Successfully moved to spawn"));
|
||||||
.add(0, 20, 0);
|
|
||||||
player.teleportAsync(safeSpawnLocation);
|
|
||||||
player.sendMessage(Component
|
|
||||||
.text("Successfully moved to spawn"));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue