package de.viper.survivalplus.commands;

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

public class DelWarpCommand implements CommandExecutor {

    private final SurvivalPlus plugin;
    private final WarpManager warpManager;

    public DelWarpCommand(SurvivalPlus plugin, WarpManager warpManager) {
        this.plugin = plugin;
        this.warpManager = warpManager;
    }

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

        Player player = (Player) sender;

        if (args.length < 1) {
            player.sendMessage(ChatColor.RED + "Benutze: /delwarp <name>");
            return true;
        }

        String warpName = args[0];
        boolean removed = warpManager.removeWarp(player.getName(), warpName);

        if (removed) {
            player.sendMessage(ChatColor.GREEN + "Warp '" + warpName + "' wurde gelöscht.");
        } else {
            player.sendMessage(ChatColor.RED + "Du hast keinen Warp mit dem Namen '" + warpName + "'.");
        }
        return true;
    }
}
