package de.viper.survivalplus.commands;

import de.viper.survivalplus.SurvivalPlus;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.Location;
import org.bukkit.World;

public class SpawnCommand implements CommandExecutor {

    private final SurvivalPlus plugin;

    public SpawnCommand(SurvivalPlus plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(plugin.getMessage("spawn.only_player"));
            return true;
        }

        Player player = (Player) sender;
        World world = player.getWorld();
        Location spawnLocation = world.getSpawnLocation();

        if (spawnLocation == null) {
            player.sendMessage(plugin.getMessage("spawn.no_spawn_found"));
            return true;
        }

        player.teleport(spawnLocation);
        player.sendMessage(plugin.getMessage("spawn.teleported"));
        return true;
    }
}
