import { system, world } from "@minecraft/server";

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        
        if (player.hasTag('dash_unlocked') && player.hasTag('dash') && !player.hasTag('dashused')) {
            
            const direcaoDaVisao = player.getViewDirection();

            player.runCommandAsync("playsound dash @a[r=6] ~~~");
            player.applyKnockback(
                direcaoDaVisao.x,
                direcaoDaVisao.z,
                4,
                0.5
            );
            player.runCommandAsync("particle nb:dash_poeira ^ ^-0.2 ^-0.1");
            player.runCommandAsync("particle nb:dash_poeira ^ ^-0.3 ^-0.2");

            player.removeTag('dash');
            player.addTag('dashused');
            
            player.runCommandAsync("particle nb:dash_poeira ^ ^-0.3 ^-0.2");
        
        } else if (player.hasTag('dashused') && player.isOnGround) {
            
            player.removeTag('dashused');
        }
    }
});