import { world, system } from "@minecraft/server";
import { CONSUMOS, CLANS, SUSANOOS, MANGEKYOU_DEFS, EXTRAS, BIJUUS, RINNEGANS, MASCARAS, EXTRASS } from "./config.js";

const RANKS = [
    "Shinobi", "Genin", "Chunin", "Jonin", "Anbu", "Monarca", "Nukenin", "Hokage", "Deus",
    "Mizukage", "Kazekage", "Tsuchikage", "Raikage", "VIP", "Akatsuki", "Kara", "7-Espadas", "Renegado"
];


function distance(a, b) {
    
    const dx = a.x - b.x;
    const dy = a.y - b.y;
    const dz = a.z - b.z;
    return Math.sqrt(dx * dx + dy * dy + dz * dz);
}

export function setDashScore(player, val) {
    try {
        player.runCommandAsync(`scoreboard players set @s dash ${val}`);
    } catch { }
}

export function addDashScore(player, delta) {
    try {
        player.runCommandAsync(`scoreboard players add @s dash ${delta}`);
    } catch { }
}

export function getDashScore(player) {
    try {
        const o = world.scoreboard.getObjective("dash");
        if (!o) {
            try { world.scoreboard.addObjective("dash", "dash"); } catch { }
            return 0;
        }
        return o.getScore(player) || 0;
    } catch {
        return 0;
    }
}

function initScoreboards() {
    const objectives = [
        "TP", "Lvl", "XP", "Stamina",
        "forca", "forca_up", "vida", "vida_up",
        "defesa", "defesa_up", "dash"   
    ];
    objectives.forEach(obj => {
        if (!world.scoreboard.getObjective(obj)) {
            try {
                world.scoreboard.addObjective(obj, obj);
            } catch { }
        }
    });
}

initScoreboards();

export function getScore(player, obj) {
    try {
        const o = world.scoreboard.getObjective(obj);
        if (!o) {
            try { world.scoreboard.addObjective(obj, obj); } catch { }
            return 0;
        }
        return o.getScore(player) || 0;
    } catch {
        return 0;
    }
}

export function setScore(player, obj, val) {
    try {
        player.runCommandAsync(`scoreboard players set @s ${obj} ${val}`);
    } catch { }
}

export function addScore(player, obj, delta) {
    try {
        player.runCommandAsync(`scoreboard players add @s ${obj} ${delta}`);
    } catch { }
}

export function getProp(player, name) {
    return parseInt(player.getDynamicProperty(name)) || 0;
}

export function setProp(player, name, val) {
    player.setDynamicProperty(name, val);
}
export function getClan(player) {
    const list = Object.keys(CLANS);
    const clanEncontrado = list.find((clan) =>
        player.hasTag(clan) || player.hasTag(clan.toLowerCase())
    );
    return clanEncontrado || null;
}

export function formatarNomeJutsu(id) {
    return id.replace("nz:", "").replace(/_/g, " ").toUpperCase();
}

world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
    try {
        if (initialSpawn && !player.hasTag("first_join_done")) {
            player.runCommandAsync(`event entity @s test:custom16`);
            player.addTag("first_join_done");
            player.sendMessage("§2Bem Vindo a Naruto Zenkai, By:Tio-Lp!");
        }
    } catch (err) { }
});

export function calcularConsumo(player) {
    let consumoChakra = 0;
    let consumoStamina = 0;
    for (const tag of player.getTags()) {
        if (tag.startsWith("modo_") && tag.endsWith("_ativo")) {
            const modoId = tag.replace("modo_", "").replace("_ativo", "");
            const valor = CONSUMOS[modoId];
            if (valor) {
                if (typeof valor === "object" && valor.stamina) {
                    consumoStamina += valor.stamina;
                } else {
                    consumoChakra += valor;
                }
            }
        }

        if (tag === "npc_aburame_proximo") {
            consumoChakra += CONSUMOS.npc_aburame_proximo;
        }
    }
    return {
        consumoChakra,
        consumoStamina
    };
}

export function limparItensModo(player) {
    const itemsToRemove = [
        "nz:kirin", 
        "nz:8_trigramas_rotacao", 
        "nz:8_trigramas_rotacao_reset",
        "nz:apagar_amaterasu", 
        "nz:jutsu_amaterasu", 
        "nz:kotoamatsukami",
        "nz:mangekyou_genjutsu", 
        "nz:sha_genjutsu", 
        "nz:expansao_parcial1",
        "nz:expansao_parcial2", 
        "nz:expansao_parcial3", 
        "nz:remover_expansao1",
        "nz:bijuudama",
        "nz:shinra_tensei",
        "nz:selar",
        "nz_sasuke:shield",
        "nz:kamui_",
        "nz:bala_de_crystal", 
        "nz:dragao_de_crystal", 
        "nz:shuriken_papel", 
        "nz:bomba_c1", 
        "nz:argila", 
        "nz:bomba_c2_j", 
        "nz:cano_bolha",
        "nz:marionete_kazekage", 
        "nz:aurela_de_papel",
        "nz:crystal_sword", 
        "minecraft:totem_of_undying",
        "nz:rasen_shuriken",
        "nz:rinne_genjutsu",
        "nz:shakujo_naruto", 
        "nz:shakujo_obito", 
        "nz:shakujo_madara",
        "nz:braco_danzou_selado", 
        "nz:braco_danzou_liberado", 
        "nz:inseto_aburame"
    ];

    const inv = player.getComponent("minecraft:inventory").container; 
    for (let i = 0; i < inv.size; i++) {
        const item = inv.getItem(i);
        if (item && itemsToRemove.includes(item.typeId)) {
            player.runCommandAsync(`clear @s ${item.typeId}`);
        }
    }
}

export function desativarTodosModos(player) {
    const tags = player.getTags().filter(tag => tag.startsWith("modo_") && tag.endsWith("_ativo"));
    for (const tag of tags) {
        player.removeTag(tag);
        player.runCommandAsync(`replaceitem entity @s slot.armor.head 0 air 1`);
        player.runCommandAsync(`replaceitem entity @s slot.armor.chest 0 air 1`);
        player.runCommandAsync(`replaceitem entity @s slot.armor.feet 0 air 1`);
    }
    limparItensExtras(player);
}

export function desativarOutrosModos(player, clan, modoAtivadoId) {
    const data = CLANS[clan];
    if (data) {
        const allModos = [...(data.modos || [])];
        if (clan === "Uchiha") {
            for (const def of MANGEKYOU_DEFS) {
                if (player.hasTag(`mangekyou_${def.key}_unlocked`)) {
                    allModos.push({ id: def.id });
                }
            }
        }
        allModos.forEach((m) => {
            if (m.id && m.id !== modoAtivadoId) {
                const idNorm = m.id.replace("nz:", "");
                player.removeTag(`modo_${idNorm}_ativo`);

                const slot = getModeSlot(m.id);
                if (slot === getModeSlot(modoAtivadoId)) {
                    player.runCommandAsync(`replaceitem entity @s ${slot} 0 air 1`);
                }
            }
        });
    }

    if (modoAtivadoId.includes("susanoo")) {
        Object.values(SUSANOOS).forEach((susanoo) => {
            [...susanoo.evolutions, { id: susanoo.baseItem }].forEach((ev) => {
                if (ev.id !== modoAtivadoId) {
                    const idNorm = ev.id.replace("nz:", "");
                    player.removeTag(`modo_${idNorm}_ativo`);
                    player.runCommandAsync(`replaceitem entity @s slot.armor.chest 0 air 1`);
                }
            });
        });
    }

    limparItensExtras(player); 
}

function getChancePorRank(player) {
  // Defina as chances por rank
  const chances = {
    "Genin": 0.001,     // 0,1%
    "Chunin": 0.01,     // 1%
    "Anbu": 0.03,       // 3%
    "Renegado": 0.03,       // 3%
    "Jonin": 0.05,      // 5%
    "Hokage": 0.8,     // 8%
    "Kazekage": 0.8,    // 8%
    "Mizukage": 0.8,   // 8%
    "Tsuchikage": 0.8,    // 8%
    "Akatsuki ": 0.10,  // 10%
    "Raikage": 0.8
  };

  // Procura qual rank o jogador tem
  const tags = player.getTags();
  for (const rank in chances) {
    if (tags.includes(rank)) {
      return chances[rank];
    }
  }

  // Se nao tiver rank, usa um valor padrao bem baixo
  return 0.001;
}

async function tentarSelar(player) {
  let chakra = getProp(player, "chakraCarga") || 0;

  // Sempre toca a anima??o ao tentar selar
  await player.runCommandAsync(`playanimation @s animation.selar`);

  // Aguarda 1 segundo (20 ticks) antes de prosseguir
  system.runTimeout(() => {
    const nearbyPlayers = world.getPlayers().filter(p =>
      p !== player &&
      distance(p.location, player.location) <= 10 &&
      p.getTags().some(t => t.startsWith("jinchuuriki_"))
    );

    const bijuusIds = [
      "nz:shukaku", "nz:matatabi", "nz:son_goku", "nz:isobu",
      "nz:kokuo", "nz:saiken", "nz:chomei", "nz:gyuki", "nz:kurama"
    ];
    const nearbyEntities = player.dimension.getEntities().filter(e =>
      bijuusIds.includes(e.typeId) &&
      distance(e.location, player.location) <= 10
    );

    if (nearbyPlayers.length === 0 && nearbyEntities.length === 0) {
      player.sendMessage("§eNao ha nenhum Jinchuuriki ou Bijuu proximo para selar.");
      return;
    }

    if (chakra < 150) {
      player.sendMessage("§4Voce nao tem chakra suficiente para usar o selo!");
      return;
    }
    setProp(player, "chakraCarga", chakra - 150);

    // Usa chance baseada no rank
    const chanceSelar = getChancePorRank(player);
    const sucesso = Math.random() <= chanceSelar;

    // Caso seja um jogador pr?ximo
    if (nearbyPlayers.length > 0) {
      const target = nearbyPlayers[0];
      const jinTag = target.getTags().find(t => t.startsWith("jinchuuriki_"));

      if (!sucesso || !jinTag) {
        player.sendMessage("§4Sua tentativa de selar falhou.");
        target.sendMessage("§eTentaram roubar sua Bijuu, mas falharam.");
        return;
      }

      target.removeTag(jinTag);
      player.addTag(jinTag);

      const nomeBijuu = jinTag.replace("jinchuuriki_", "");
      player.sendMessage(`§2Voce roubou a Bijuu (${nomeBijuu}) de ${target.name}!`);
      target.sendMessage(`§4Voce foi roubado! Sua Bijuu (${nomeBijuu}) foi selada em outro ninja!`);

      limparItemBijuu(player, nomeBijuu);

      player.runCommandAsync(`scoreboard players add @s gedo_mazou 1`);
      return;
    }

    // Caso seja uma entidade Bijuu pr?xima
    if (nearbyEntities.length > 0) {
      const mob = nearbyEntities[0];
      const mobId = mob.typeId.replace("nz:", "");

      if (!sucesso) {
        player.sendMessage("§4Sua tentativa de selar falhou.");
        return;
      }

      let jinTag;
      if (mobId === "son_goku") {
        jinTag = "jinchuuriki_songoku";
      } else {
        jinTag = `jinchuuriki_${mobId}`;
      }

      player.addTag(jinTag);
      player.sendMessage(`§2Voce selou a Bijuu (${mobId})!`);

      limparItemBijuu(player, mobId);

      player.runCommandAsync(`scoreboard players add @s gedo_mazou 1`);

      if (mob.kill) {
        mob.kill();
      } else {
        mob.runCommandAsync("kill @s").catch(() => { });
      }
      return;
    }
  }, 20); // espera 20 ticks = 1 segundo
}

function limparItemBijuu(player, bijuuId) {
    const inv = player.getComponent("minecraft:inventory").container;

    
    if (bijuuId === "kurama") {
        const kuramaItens = ["nz:alma_kurama_yin", "nz:alma_kurama_yang"];
        for (let i = 0; i < inv.size; i++) {
            const item = inv.getItem(i);
            if (!item) continue;
            if (kuramaItens.includes(item.typeId)) {
                inv.setItem(i, undefined);
                break; 
            }
        }
        return;
    }

    
    const almaItem = `nz:alma_${bijuuId}`;
    for (let i = 0; i < inv.size; i++) {
        const item = inv.getItem(i);
        if (!item) continue;
        if (item.typeId === almaItem) {
            inv.setItem(i, undefined);
            break;
        }
    }
}

world.afterEvents.itemUse.subscribe(({ source, itemStack }) => {
    try {
        if (!source || source.typeId !== "minecraft:player") return;
        if (!itemStack || itemStack.typeId !== "nz:selar") return;

        tentarSelar(source);
    } catch (err) {
        source.sendMessage("§cErro ao tentar usar o selo: " + err);
    }
});

export function atualizarXP(player) {
    let xp = getScore(player, "XP");
    let lvl = getScore(player, "Lvl") || 1;
    const xpNec = 30 + (lvl - 1) * 25;

    if (xp >= xpNec) {
        xp -= xpNec;
        lvl += 1;
        setScore(player, "XP", xp);
        setScore(player, "Lvl", lvl);
        player.sendMessage(`§6Voce subiu para o nivel §e${lvl}§6!`);

        let chakraMax = getProp(player, "chakraMax") || 100;
        let staminaMax = getProp(player, "staminaMax") || 100;

        chakraMax += 20;
        staminaMax += 20;

        setProp(player, "chakraMax", chakraMax);
        setProp(player, "staminaMax", staminaMax);

        if (player.hasTag("mangekyou_sasuke_unlocked") && player.hasTag("mangekyou_itachi_unlocked") && !player.hasTag("mangekyou_eterno_sasuke_unlocked")) {
            player.addTag("mangekyou_eterno_sasuke_unlocked");
            player.sendMessage("§aDesbloqueado Mangekyou Eterno Sasuke!");
        }
        if (player.hasTag("mangekyou_lp_unlocked") && player.hasTag("mangekyou_kaiser_unlocked") && !player.hasTag("mangekyou_eterno_lp_unlocked")) {
            player.addTag("mangekyou_eterno_lp_unlocked");
            player.sendMessage("§aDesbloqueado Mangekyou Eterno LP!");
        }
        if (player.hasTag("mangekyou_lp_unlocked") && player.hasTag("mangekyou_kaiser_unlocked") && !player.hasTag("mangekyou_eterno_kaiser_unlocked")) {
            player.addTag("mangekyou_eterno_kaiser_unlocked");
            player.sendMessage("§aDesbloqueado Mangekyou Eterno Kaiser!");
        }
        if (player.hasTag("mangekyou_madara_unlocked") && player.hasTag("mangekyou_izuna_unlocked") && !player.hasTag("mangekyou_eterno_madara_unlocked")) {
            player.addTag("mangekyou_eterno_madara_unlocked");
            player.sendMessage("§aDesbloqueado Mangekyou Eterno Madara!");
        }
        if (player.hasTag("mangekyou_kakashi_unlocked") && player.hasTag("mangekyou_obito_unlocked") && !player.hasTag("mangekyou_mangekyou_duplo_unlocked")) {
            player.addTag("mangekyou_mangekyou_duplo_unlocked");
            player.sendMessage("§aDesbloqueado Mangekyou Duplo!");
        }
    }
    return xpNec;
}

const BIJUU_CHAKRA_BONUS = {
    "jinchuuriki_shukaku": 1300,
    "jinchuuriki_matatabi": 1800,
    "jinchuuriki_isobu": 2300,
    "jinchuuriki_songoku": 2900,
    "jinchuuriki_kokuo": 3300,
    "jinchuuriki_saiken": 4000,
    "jinchuuriki_chomei": 4300,
    "jinchuuriki_gyuki": 4800,
    "jinchuuriki_kurama": 5200,
    "jinchuuriki_juubi": 9000
};

function atualizarBijuuChakra(player) {
    let chakraMax = getProp(player, "chakraMax") || 0;

    for (const [tag, bonus] of Object.entries(BIJUU_CHAKRA_BONUS)) {
        const appliedKey = `bijuu_${tag}_applied`;

        if (player.hasTag(tag)) {
            if (!getProp(player, appliedKey)) {
                setProp(player, "chakraMax", chakraMax + bonus);
                setProp(player, appliedKey, 1);
                player.sendMessage(`§aVoce recebeu o chakra da ${tag.replace("jinchuuriki_", "")}! (+${bonus})`);
            }
        } else {
            if (getProp(player, appliedKey)) {
                setProp(player, "chakraMax", chakraMax - bonus);
                setProp(player, appliedKey, 0);
                player.sendMessage(`§4Voce perdeu o chakra da ${tag.replace("jinchuuriki_", "")}! (-${bonus})`);
            }
        }
    }
}

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        atualizarBijuuChakra(player);
    }
}, 20);

export function iniciarSistemas() {
    system.runInterval(() => {
        for (const player of world.getPlayers()) {
            try {
                const health = player.getComponent("health")?.currentValue ?? 20;
                const chakra = getProp(player, "chakraCarga") ?? 0;
                const chakraMax = getProp(player, "chakraMax") ?? 100;
                const stamina = getScore(player, "Stamina") ?? 0;
                const staminaMax = getProp(player, "staminaMax") ?? 100;
                const karma = getScore(player, "karma") ?? 0;
                const xp = getScore(player, "XP") ?? 0;
                const xpNec = atualizarXP(player) ?? 100;
                const tp = getScore(player, "TP") ?? 0;
                const ryo = getScore(player, "Ryo") ?? 0;

                const rank = player.getTags().find(t => RANKS.includes(t)) || "Sem Rank";

                
                let karmaColor = "§6"; 
                if (karma >= 650) karmaColor = "§a";       
                else if (karma >= 325 && karma <= 650) karmaColor = "§e"; 
                else if (karma >= 0 && karma <= 325) karmaColor = "§c";  
                else if (karma < 0) karmaColor = "§5";   

                player.onScreenDisplay.setActionBar(
                    `§4[V-${Math.floor(health)}] §3[TP-${tp}] §2[Ryo-${ryo}]\n§a[R-${rank}] ${karmaColor}[K-${karma}] §e[XP-${xp}/${xpNec}]\n§b[CH-${chakra}/${chakraMax}] §6[ST-${stamina}/${staminaMax}]`
                );
            } catch { }
        }
    }, 6);

    system.runInterval(() => {
        for (const player of world.getPlayers()) {
            try {
                let chakraCarga = getProp(player, "chakraCarga");
                const chakraMax = getProp(player, "chakraMax") || 100;
                let stamina = getScore(player, "Stamina");
                const staminaMax = getProp(player, "staminaMax") || 100;

                const { consumoChakra, consumoStamina } = calcularConsumo(player);

                if (consumoChakra > 0) {
                    chakraCarga -= consumoChakra;
                    if (chakraCarga < 0) chakraCarga = 0;
                    setProp(player, "chakraCarga", chakraCarga);
                }

                if (consumoStamina > 0) {
                    stamina -= consumoStamina;
                    if (stamina < 0) stamina = 0;
                    setScore(player, "Stamina", stamina);
                }

                if (chakraCarga <= 0 || stamina <= 0) {
                    desativarTodosModos(player);
                }
            } catch { }
        }
    }, 30);

    system.runInterval(() => {
        for (const p of world.getPlayers()) {
            if (p.isSneaking) {
                let c = getProp(p, "chakraCarga"),
                    cm = getProp(p, "chakraMax") || 100,
                    s = getScore(p, "Stamina"),
                    sm = getProp(p, "staminaMax") || 100;

                const lvl = getScore(p, "Lvl") || 1;
                const chakraRegen = 15 + ((lvl - 1) * 2);

                if (c < cm) setProp(p, "chakraCarga", Math.min(c + chakraRegen, cm));
                if (s < sm) setScore(p, "Stamina", Math.min(s + 15, sm));
            }
        }
    }, 20);

    system.runInterval(() => {
        for (const p of world.getPlayers()) {
            if (!p.isSneaking) {
                let c = getProp(p, "chakraCarga"),
                    cm = getProp(p, "chakraMax") || 100,
                    s = getScore(p, "Stamina"),
                    sm = getProp(p, "staminaMax") || 100;

                if (c < cm) setProp(p, "chakraCarga", Math.min(c + 1, cm));
                if (s < sm) setScore(p, "Stamina", Math.min(s + 1, sm));
            }
        }
    }, 100);
}

export function getModeSlot(modeId) {
    // caso especial primeiro
    if (modeId === "nz:karma_boruto_v1") {
        return "slot.armor.head"; // Boruto Karma no capacete
    }

    if (
        modeId.includes("susanoo") ||
        modeId.includes("karma") ||
        modeId.includes("portao") ||
        modeId.includes("crystal") ||
        modeId === "nz:byakugou" ||
        modeId === "nz:jutsu_modo_trovao"
    ) {
        return "slot.armor.chest";
    }

    if (
        modeId.includes("maldicao") ||
        (modeId.includes("sennin") && modeId !== "nz:byakugou")
    ) {
        if (modeId === "nz:senju_sennin") {
            return "slot.armor.head";
        }
        return "slot.armor.feet";
    }

    return "slot.armor.head";
}

export function findModeById(id) {
    for (const c of Object.values(CLANS)) {
        const found = c.modos?.find(m => m.id === id);
        if (found) return found;
    }

    for (const group of Object.values(EXTRAS)) {
        if (Array.isArray(group)) {
            const found = group.find(m => m.id === id);
            if (found) return found;
        } else {
            for (const subGroup of Object.values(group)) {
                if (Array.isArray(subGroup)) {
                    const found = subGroup.find(m => m.id === id);
                    if (found) return found;
                }
            }
        }
    }

    for (const b of Object.values(BIJUUS)) {
        const found = b.modos.find(m => m.id === id);
        if (found) return found;
    }

    const mg = MANGEKYOU_DEFS.find(m => m.id === id);
    if (mg) {
        return {
            ...mg,
            icon: `textures/items/pamobile/nzmangekyou${mg.key}`
        };
    }

    for (const s of Object.values(SUSANOOS)) {
        if (s.baseItem === id) {
            return { id, name: "Susanoo Base", icon: s.baseIcon };
        }
        const found = s.evolutions.find(e => e.id === id);
        if (found) return found;
    }

    if (id === "nz:mgeternosasuke") {
        return { id, nome: "Eterno Sasuke", icon: "textures/items/pamobile/nzmgeterno_sasuke" };
    }
    if (id === "nz:mgeternomadara") {
        return { id, nome: "Eterno Madara", icon: "textures/items/pamobile/nzmgeterno_madara" };
    }
    if (id === "nz:mangekyouduplo") {
        return { id, nome: "Mangekyou Duplo", icon: "textures/items/pamobile/nzmangekyou_duplo" };
    }

    const rinne = RINNEGANS.find(r => r.id === id);
    if (rinne) return rinne;

    return null;
}

export function isSlotOccupied(player, slotNeeded, ignoreModeId = "") {
    const tags = player.getTags();

    for (const tag of tags) {
        if (tag.startsWith("modo") && tag.endsWith("ativo")) {
            const currentModeId = tag.replace("modo", "").replace("ativo", "");
            if (currentModeId === ignoreModeId) continue;

            const currentSlot = getModeSlot(currentModeId);
            if (currentSlot === slotNeeded) {
                return true;
            }
        }
    }

    for (const tag of tags) {
        if (tag.startsWith("modo") && tag.endsWith("ativo")) {
            const currentModeId = tag.replace("modo", "").replace("ativo", "");
            if (currentModeId === ignoreModeId) continue;
            player.removeTag(tag);
        }
    }

    return false;
}
export function gerenciarVisual(player, tipo, keyAlvo, idEvento) {
    const lista = tipo === "mask" ? MASCARAS : EXTRASS;
    const tagEquipadaAlvo = `${tipo}_${keyAlvo}_equipado`;
    
    if (player.hasTag(tagEquipadaAlvo)) {
        player.removeTag(tagEquipadaAlvo);
        player.runCommandAsync(`event entity @s test:${tipo}1`); 
        player.sendMessage(`§cDesequipado.`);
        
        limparItensModo(player);
        return;
    }

    Object.keys(lista).forEach(key => {
        const tag = `${tipo}_${key}_equipado`;
        if (player.hasTag(tag)) player.removeTag(tag);
    });
    
    limparItensModo(player);

    player.addTag(tagEquipadaAlvo);
    player.runCommandAsync(`event entity @s test:${tipo}${idEvento}`);
    
    if (keyAlvo === "braco_danzou_selado") player.runCommandAsync(`give @s nz:braco_danzou_selado 1 0 {"minecraft:item_lock":{"mode":"lock_in_inventory"}}`);
    if (keyAlvo === "braco_danzou_liberado") player.runCommandAsync(`give @s nz:braco_danzou_liberado 1 0 {"minecraft:item_lock":{"mode":"lock_in_inventory"}}`);

    player.sendMessage(`§aEquipado com sucesso.`);
    player.playSound("armor.equip_leather");
}