import { world } from "@minecraft/server";
import { Command } from "../../handler";
import { config, sendAllMessage, sendPlayerMessage } from "../../../config";
import { getPlayer, setScore } from "../../../lifesteal";

new Command({
    name: `op`,
    staffOnly: true,
    code({ player, args }) {
        if (!args[0]) {
            if (player.hasTag(config.staffTag)) {
                player.removeTag(config.staffTag);
                sendPlayerMessage(player, `§a${player.name} is no longer lifesteal-opped!`);
                return;
            }

            sendPlayerMessage(player, `§a${player.name} is now lifesteal-opped!`);
            player.addTag(config.staffTag);
            return;
        }

        let msg = !args[1] ? args[0] : args.join(` `).split(/\"/g)[1];
        let target = getPlayer(msg);
        if (!target) return sendPlayerMessage(player, `§8[§cX§8] §cPlayer not found (${msg})`);

        if (target.hasTag(config.staffTag)) {
            sendPlayerMessage(player, `§a${target.name} is no longer lifesteal-opped!`);
            target.removeTag(config.staffTag);
            return;
        }

        target.addTag(config.staffTag);
        sendPlayerMessage(player, `§a${target.name} is now lifesteal-opped!`);
    },
});