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.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

public class ClearDebugArmorStandsCommand implements CommandExecutor {

    private final SurvivalPlus plugin;

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

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

        Player player = (Player) sender;
        int removedCount = 0;

        for (Entity entity : player.getWorld().getEntities()) {
            if (entity instanceof ArmorStand) {
                ArmorStand armorStand = (ArmorStand) entity;
                armorStand.setInvulnerable(false);
                armorStand.setMarker(false);
                armorStand.setGravity(true);
                armorStand.remove();
                removedCount++;
            }
        }

        player.sendMessage("Es wurden " + removedCount + " ArmorStands entfernt.");
        return true;
    }
}
