import { world, Player, system } from '@minecraft/server';
import { Command } from '../../handler';
import { sendPlayerMessage, config } from '../../../config';
import { deadplayers, getPlayer, getScore, random, revivelist } from '../../../lifesteal';

export function forceReviveHelp(player: Player) {
    sendPlayerMessage(player, `§e§lLifesteal Help Page -- Forcerevive§r§6
> Revive a dead player with no heart of life

> Usage: ${config.prefix}forcerevive <player>

> Examples: [
${config.prefix}forcerevive ${player.name}
]`);
}

new Command({
    name: `forcerevive`,
    staffOnly: true,
    code({ player, args }) {
        if (!args[0]) return forceReviveHelp(player);
        let target: string;
        for (let x of deadplayers.keys()) {
            if (x.toLowerCase() == args.join(` `).toLowerCase()) {
                target = x;
                break;
            }
        }
        if (!target) {
            for (let players of world.getAllPlayers()) {
                if (players.name.toLowerCase() == args.join(` `).toLowerCase()) return sendPlayerMessage(player, `§cThat player is not a ghost!`);
            }
            return sendPlayerMessage(player, `§cFailed to find player, the player must be a ghost`);
        }

        revivelist.set(`${target.toLowerCase()}`, `${target.toLowerCase()}.,${player.name}`);
        deadplayers.delete(target);
        sendPlayerMessage(player, `§aRevived §f${target}`);
    },
});