package com.playerblocklife;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 * CheckLifeBlocksCommand - 显示玩家在PlayerBlockLife游戏模式下的生命方块状态
 * 
 * <p>在PlayerBlockLife游戏模式下，此命令显示玩家当前的剩余生命方块数、游戏状态和分配的颜色。
 * 与旧模式不同，此命令不再显示生命方块的具体位置，而是提供当前游戏状态信息。</p>
 * 
 * @author xiaobai
 * @version 2.2.0-1.20.4
 * @since 1.0.0
 */
public class CheckLifeBlocksCommand implements CommandExecutor {
    private final PlayerBlockLife plugin;

    /**
     * 构造一个新的检查生命方块命令执行器
     * 
     * @param plugin 插件主类实例
     */
    public CheckLifeBlocksCommand(PlayerBlockLife plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "此命令只能由玩家执行！控制台无法查看具体玩家的生命方块状态。");
            return true;
        }

        Player player = (Player) sender;

        // 获取当前玩家在新模式下的剩余方块数
        int remainingBlocks = plugin.getGameStateManager().getRemainingBlocks(player.getUniqueId());
        
        player.sendMessage(ChatColor.AQUA + "=== 你的生命方块状态 ===");
        player.sendMessage(ChatColor.GRAY + "剩余方块数量: " + ChatColor.YELLOW + remainingBlocks + 
                          ChatColor.GRAY + " / " + ChatColor.RED + 5);
        
        // 根据游戏状态显示不同信息
        GameStateManager.GameState state = plugin.getGameStateManager().getCurrentState();
        switch (state) {
            case WAITING:
                player.sendMessage(ChatColor.YELLOW + "游戏状态: 等待开始");
                break;
            case STARTED:
                player.sendMessage(ChatColor.GREEN + "游戏状态: 进行中");
                break;
            case FINISHED:
                player.sendMessage(ChatColor.RED + "游戏状态: 已结束");
                break;
        }
        
        // 显示玩家颜色
        org.bukkit.Material playerColor = plugin.getGameStateManager().getPlayerColor(player.getUniqueId());
        if (playerColor != null) {
            String colorName = getColorName(playerColor);
            player.sendMessage(ChatColor.GRAY + "你的方块颜色: " + ChatColor.AQUA + colorName);
        }
        
        return true;
    }
    
    /**
     * 获取材料颜色名称
     */
    private String getColorName(org.bukkit.Material material) {
        String name = material.name();
        if (name.contains("WHITE")) return "白色";
        if (name.contains("ORANGE")) return "橙色";
        if (name.contains("MAGENTA")) return "品红色";
        if (name.contains("LIGHT_BLUE")) return "淡蓝色";
        if (name.contains("YELLOW")) return "黄色";
        if (name.contains("LIME")) return "黄绿色";
        if (name.contains("PINK")) return "粉色";
        if (name.contains("GRAY")) return "灰色";
        if (name.contains("LIGHT_GRAY")) return "淡灰色";
        if (name.contains("CYAN")) return "青色";
        if (name.contains("PURPLE")) return "紫色";
        if (name.contains("BLUE")) return "蓝色";
        if (name.contains("BROWN")) return "棕色";
        if (name.contains("GREEN")) return "绿色";
        if (name.contains("RED")) return "红色";
        if (name.contains("BLACK")) return "黑色";
        return "未知";
    }
}