mirror of
https://github.com/kaboomserver/extras.git
synced 2024-05-20 20:11:21 +00:00
Fix cross-dimensional /spawn
This commit is contained in:
parent
c57beec377
commit
52f1c09070
|
@ -2,10 +2,9 @@ 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.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -13,6 +12,7 @@ import org.bukkit.command.ConsoleCommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import pw.kaboom.extras.Main;
|
||||
import pw.kaboom.extras.platform.PlatformScheduler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
@ -28,35 +28,21 @@ public final class CommandSpawn implements CommandExecutor {
|
|||
}
|
||||
|
||||
final Player player = (Player) sender;
|
||||
final World playerWorld = player.getWorld();
|
||||
final World defaultWorld = Bukkit.getWorld("world");
|
||||
final World world = (defaultWorld == null) ? Bukkit.getWorlds().get(0) : defaultWorld;
|
||||
final Location spawnLocation = world.getSpawnLocation();
|
||||
final Chunk chunk = spawnLocation.getChunk();
|
||||
final Main plugin = JavaPlugin.getPlugin(Main.class);
|
||||
|
||||
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"));
|
||||
});
|
||||
|
||||
if (!world.equals(playerWorld) && plugin.isFolia()) {
|
||||
sender.sendMessage(Component
|
||||
.text("Cross-dimensional teleports are currently unsupported on Folia."));
|
||||
return true;
|
||||
}
|
||||
|
||||
final Location spawnLocation = world.getSpawnLocation();
|
||||
final int maxWorldHeight = 256;
|
||||
|
||||
for (double y = spawnLocation.getY(); y <= maxWorldHeight; y++) {
|
||||
final Location yLocation = new Location(world, spawnLocation.getX(), y,
|
||||
spawnLocation.getZ());
|
||||
final Block coordBlock = world.getBlockAt(yLocation);
|
||||
|
||||
if (!coordBlock.getType().isSolid()
|
||||
&& !coordBlock.getRelative(BlockFace.UP).getType().isSolid()) {
|
||||
player.teleportAsync(yLocation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(Component
|
||||
.text("Successfully moved to spawn"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue