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 reviveAllHelp(player: Player) {
    sendPlayerMessage(player, `§e§lLifesteal Help Page -- Reviveall§r§6
> Revive all dead players

> Usage: ${config.prefix}reviveall

> Examples: [
${config.prefix}reviveall
]`);
}

new Command({
    name: `reviveall`,
    staffOnly: true,
    code({ player }) {
        sendPlayerMessage(player, `§aAre you sure you want to revive all dead players? §fYes | No`);
        let event = world.beforeEvents.chatSend.subscribe(data => {
            if (data.sender == player) {
                data.cancel = true;
                if (data.message.toLowerCase() == `yes`) {
                    system.run(() => {
                        world.beforeEvents.chatSend.unsubscribe(event);
                    });
                    sendPlayerMessage(player, `§aPlease wait..`);
                    for (let x of deadplayers.keys()) {
                        revivelist.set(x.toLowerCase(), x.toLowerCase());
                        deadplayers.delete(x);
                    }
                    sendPlayerMessage(player, `§aRevived all dead players!`);
                }
                else {
                    sendPlayerMessage(player, `§cCanceled revive all`);
                    system.run(() => {
                        world.beforeEvents.chatSend.unsubscribe(event);
                    });
                }
            }
        });
        system.runTimeout(() => {
            world.beforeEvents.chatSend.unsubscribe(event);
        }, 200);
    },
});