2019-12-17 12:37:59 +00:00
|
|
|
package pw.kaboom.extras.commands;
|
2019-07-30 14:41:54 +00:00
|
|
|
|
2022-05-21 19:28:42 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2019-07-30 14:41:54 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2019-09-22 02:37:43 +00:00
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
2019-07-30 14:41:54 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2023-03-30 18:30:26 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import pw.kaboom.extras.Main;
|
2023-03-31 15:45:43 +00:00
|
|
|
import pw.kaboom.extras.platform.PlatformScheduler;
|
2019-07-30 14:41:54 +00:00
|
|
|
|
2022-05-21 19:28:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2019-12-21 13:39:31 +00:00
|
|
|
public final class CommandSpawn implements CommandExecutor {
|
2022-05-21 19:28:42 +00:00
|
|
|
public boolean onCommand(final @Nonnull CommandSender sender,
|
|
|
|
final @Nonnull Command command,
|
|
|
|
final @Nonnull String label,
|
2022-05-20 03:07:38 +00:00
|
|
|
final String[] args) {
|
2022-05-20 02:35:48 +00:00
|
|
|
if (sender instanceof ConsoleCommandSender) {
|
2022-05-21 19:28:42 +00:00
|
|
|
sender.sendMessage(Component
|
|
|
|
.text("Command has to be run by a player"));
|
2022-10-16 00:08:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-05-20 02:35:48 +00:00
|
|
|
|
2022-10-16 00:08:32 +00:00
|
|
|
final Player player = (Player) sender;
|
|
|
|
final World defaultWorld = Bukkit.getWorld("world");
|
|
|
|
final World world = (defaultWorld == null) ? Bukkit.getWorlds().get(0) : defaultWorld;
|
|
|
|
final Location spawnLocation = world.getSpawnLocation();
|
2022-05-20 02:35:48 +00:00
|
|
|
|
2023-03-31 15:59:37 +00:00
|
|
|
world.getChunkAtAsync(spawnLocation).thenAccept(chunk -> {
|
|
|
|
final Main plugin = JavaPlugin.getPlugin(Main.class);
|
|
|
|
final Location highestSpawnLocation = world.getHighestBlockAt(spawnLocation)
|
|
|
|
.getLocation()
|
|
|
|
.add(0, 1, 0);
|
2023-03-31 15:49:36 +00:00
|
|
|
|
2023-03-31 15:59:37 +00:00
|
|
|
PlatformScheduler.executeOnEntity(plugin, player, () -> {
|
|
|
|
player.teleportAsync(highestSpawnLocation);
|
|
|
|
player.sendMessage(Component.text("Successfully moved to spawn"));
|
2023-03-31 15:49:36 +00:00
|
|
|
});
|
2023-03-31 15:45:43 +00:00
|
|
|
});
|
2022-10-16 00:08:32 +00:00
|
|
|
|
2022-05-20 02:35:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-30 14:41:54 +00:00
|
|
|
}
|