package de.viper.survivalplus.commands;

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

public class SetWorldSpawnCommand implements CommandExecutor {

    private final SurvivalPlus plugin;

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

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage(ChatColor.RED + "Dieser Befehl kann nur von einem Spieler verwendet werden.");
            return true;
        }

        if (!player.hasPermission("survivalplus.setworldspawn")) {
            player.sendMessage(ChatColor.RED + "Du hast keine Rechte für diesen Befehl.");
            return true;
        }

        Location loc = player.getLocation();
        World world = player.getWorld();
        world.setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
        player.sendMessage(ChatColor.GREEN + "Spawnpunkt gesetzt bei §e" +
                loc.getBlockX() + " " + loc.getBlockY() + " " + loc.getBlockZ());

        return true;
    }
}
