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

world.afterEvents.playerSpawn.subscribe((data) => {
    for (const player of world.getAllPlayers()) {
        player.setDynamicProperty("w_aps_hasHelmet", false)
        player.setDynamicProperty("w_aps_hasChest", false)
        player.setDynamicProperty("w_aps_hasLeggings", false)
        player.setDynamicProperty("w_aps_hasBoots", false)
        player.runCommand(`execute as @a[tag=!wonder_aps_joined] run execute positioned as @s run structure load wonder_aps:aps_guide_book ~ ~ ~`)
        player.runCommand(`execute as @a[tag=!wonder_aps_joined] run tag @s add wonder_aps_joined`)
    }
});

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {

        var inv = player.getComponent("equippable");
        var eHead = inv?.getEquipment("Head");
        var eChest = inv?.getEquipment("Chest");
        var eLegs = inv?.getEquipment("Legs");
        var eFeet = inv?.getEquipment("Feet");

        var w_aps_hasHelmet = player.getDynamicProperty("w_aps_hasHelmet")
        var w_aps_hasChest = player.getDynamicProperty("w_aps_hasChest")
        var w_aps_hasLeggings = player.getDynamicProperty("w_aps_hasLeggings")
        var w_aps_hasBoots = player.getDynamicProperty("w_aps_hasBoots")

        // HELMET UI

        if ((eHead != undefined) && (w_aps_hasHelmet != undefined)) {
            var checkHead = eHead.typeId
            if ((checkHead == "wonder_aps:wonder_aps_nano_suit_helmet") || (checkHead == "wonder_aps:wonder_aps_nano_suit_red_helmet") || (checkHead == "wonder_aps:wonder_aps_nano_suit_yellow_helmet") || (checkHead == "wonder_aps:wonder_aps_giga_suit_helmet") || (checkHead == "wonder_aps:wonder_aps_giga_suit_pink_helmet") || (checkHead == "wonder_aps:wonder_aps_power_suit_helmet") || (checkHead == "wonder_aps:wonder_aps_power_suit_lime_helmet") || (checkHead == "wonder_aps:wonder_aps_power_suit_orange_helmet") || (checkHead == "wonder_aps:wonder_aps_power_suit_silver_helmet") || (checkHead == "wonder_aps:wonder_aps_super_suit_helmet") || (checkHead == "wonder_aps:wonder_aps_super_suit_black_helmet") || (checkHead == "wonder_aps:wonder_aps_super_suit_green_helmet") || (checkHead == "wonder_aps:wonder_aps_super_suit_tan_helmet") || (checkHead == "wonder_aps:wonder_aps_sun_suit_silver_helmet") || (checkHead == "wonder_aps:wonder_aps_sun_suit_bronze_helmet") || (checkHead == "wonder_aps:wonder_aps_void_suit_helmet") || (checkHead == "wonder_aps:wonder_aps_void_suit_lime_helmet") || (checkHead == "wonder_aps:wonder_aps_proto_suit_helmet") || (checkHead == "wonder_aps:wonder_aps_proto_suit_black_helmet") || (checkHead == "wonder_aps:wonder_aps_proto_suit_green_helmet") || (checkHead == "wonder_aps:wonder_aps_proto_suit_silver_helmet")) {
                if (w_aps_hasHelmet.toString() === "false") {
                    player.runCommand(`playsound wonder_aps:helmet_on @s`)
                    player.setDynamicProperty("w_aps_hasHelmet", true)
                }
            }
            else if ((checkHead == "wonder_aps:wonder_aps_nano_suit_blue_helmet") || (checkHead == "wonder_aps:wonder_aps_giga_suit_aqua_helmet") || (checkHead == "wonder_aps:wonder_aps_giga_suit_purple_helmet") || (checkHead == "wonder_aps:wonder_aps_sun_suit_helmet") || (checkHead == "wonder_aps:wonder_aps_sun_suit_red_helmet") || (checkHead == "wonder_aps:wonder_aps_void_suit_white_helmet") || (checkHead == "wonder_aps:wonder_aps_void_suit_blue_helmet") || (checkHead == "wonder_aps:wonder_aps_warrior_suit_helmet") || (checkHead == "wonder_aps:wonder_aps_warrior_suit_black_helmet") || (checkHead == "wonder_aps:wonder_aps_warrior_suit_blue_helmet") || (checkHead == "wonder_aps:wonder_aps_warrior_suit_pink_helmet")) {
                player.runCommand(`effect @s night_vision 11 1 true`)
                player.runCommand(`effect @s water_breathing 11 1 true`)
                if (w_aps_hasHelmet.toString() === "false") {
                    player.runCommand(`playsound wonder_aps:helmet_on @s`)
                    player.setDynamicProperty("w_aps_hasHelmet", true)
                }
            }
            else if ((checkHead != "wonder_aps:wonder_aps_nano_suit_helmet") || (checkHead != "wonder_aps:wonder_aps_nano_suit_red_helmet") || (checkHead != "wonder_aps:wonder_aps_nano_suit_yellow_helmet") || (checkHead != "wonder_aps:wonder_aps_nano_suit_blue_helmet") || (checkHead != "wonder_aps:wonder_aps_giga_suit_helmet") || (checkHead != "wonder_aps:wonder_aps_giga_suit_aqua_helmet") || (checkHead != "wonder_aps:wonder_aps_giga_suit_pink_helmet") || (checkHead != "wonder_aps:wonder_aps_giga_suit_purple_helmet") || (checkHead != "wonder_aps:wonder_aps_power_suit_helmet") || (checkHead != "wonder_aps:wonder_aps_power_suit_lime_helmet") || (checkHead != "wonder_aps:wonder_aps_power_suit_orange_helmet") || (checkHead != "wonder_aps:wonder_aps_power_suit_silver_helmet") || (checkHead != "wonder_aps:wonder_aps_super_suit_helmet") || (checkHead != "wonder_aps:wonder_aps_super_suit_black_helmet") || (checkHead != "wonder_aps:wonder_aps_super_suit_green_helmet") || (checkHead != "wonder_aps:wonder_aps_super_suit_tan_helmet") || (checkHead != "wonder_aps:wonder_aps_sun_suit_helmet") || (checkHead != "wonder_aps:wonder_aps_sun_suit_red_helmet") || (checkHead != "wonder_aps:wonder_aps_void_suit_white_helmet") || (checkHead != "wonder_aps:wonder_aps_proto_suit_helmet") || (checkHead != "wonder_aps:wonder_aps_proto_suit_black_helmet") || (checkHead != "wonder_aps:wonder_aps_proto_suit_green_helmet") || (checkHead != "wonder_aps:wonder_aps_proto_suit_silver_helmet") || (checkHead != "wonder_aps:wonder_aps_warrior_suit_helmet") || (checkHead != "wonder_aps:wonder_aps_warrior_suit_black_helmet") || (checkHead != "wonder_aps:wonder_aps_warrior_suit_blue_helmet") || (checkHead != "wonder_aps:wonder_aps_warrior_suit_pink_helmet")) {
                if (w_aps_hasHelmet.toString() === "true") {
                    player.runCommand(`playsound wonder_aps:helmet_off @s`)
                    player.setDynamicProperty("w_aps_hasHelmet", false)
                }
            }
        }
        else {
            if (w_aps_hasHelmet != undefined) {
                if (w_aps_hasHelmet.toString() === "true") {
                    player.setDynamicProperty("w_aps_hasHelmet", false)
                }
            }
        }

        // BOOTS EFFECTS

        if ((eFeet != undefined) && (w_aps_hasBoots != undefined)) {
            var checkFeet = eFeet.typeId
            if ((checkFeet == "wonder_aps:wonder_aps_nano_suit_boots") || (checkFeet == "wonder_aps:wonder_aps_nano_suit_blue_boots") || (checkFeet == "wonder_aps:wonder_aps_nano_suit_red_boots") || (checkFeet == "wonder_aps:wonder_aps_giga_suit_boots") || (checkFeet == "wonder_aps:wonder_aps_giga_suit_aqua_boots") || (checkFeet == "wonder_aps:wonder_aps_giga_suit_pink_boots") || (checkFeet == "wonder_aps:wonder_aps_power_suit_boots") || (checkFeet == "wonder_aps:wonder_aps_power_suit_lime_boots") || (checkFeet == "wonder_aps:wonder_aps_power_suit_orange_boots") || (checkFeet == "wonder_aps:wonder_aps_super_suit_boots") || (checkFeet == "wonder_aps:wonder_aps_super_suit_tan_boots") || (checkFeet == "wonder_aps:wonder_aps_super_suit_green_boots") || (checkFeet == "wonder_aps:wonder_aps_sun_suit_bronze_boots") || (checkFeet == "wonder_aps:wonder_aps_sun_suit_red_boots") || (checkFeet == "wonder_aps:wonder_aps_void_suit_blue_boots") || (checkFeet == "wonder_aps:wonder_aps_void_suit_lime_boots") || (checkFeet == "wonder_aps:wonder_aps_void_suit_white_boots") || (checkFeet == "wonder_aps:wonder_aps_warrior_suit_black_boots") || (checkFeet == "wonder_aps:wonder_aps_warrior_suit_boots")) {
                player.runCommand(`effect @s slow_falling 11 2 true`)
                if (player.isJumping) {
                    player.applyKnockback(0, 0, 0, 0.4)
                }
                if (w_aps_hasBoots.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.flight_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasBoots", true)
                }
            }
            else if ((checkFeet == "wonder_aps:wonder_aps_nano_suit_yellow_boots") || (checkFeet == "wonder_aps:wonder_aps_super_suit_black_boots") || (checkFeet == "wonder_aps:wonder_aps_giga_suit_purple_boots") || (checkFeet == "wonder_aps:wonder_aps_sun_suit_boots") || (checkFeet == "wonder_aps:wonder_aps_void_suit_boots") || (checkFeet == "wonder_aps:wonder_aps_warrior_suit_pink_boots")) {
                player.runCommand(`effect @s slow_falling 11 3 true`)
                if (player.isJumping) {
                    player.applyKnockback(0, 0, 0, 0.8)
                }
                if (w_aps_hasBoots.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.flight_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasBoots", true)
                }
            }
            else if ((checkFeet == "wonder_aps:wonder_aps_power_suit_silver_boots") || (checkFeet == "wonder_aps:wonder_aps_sun_suit_silver_boots")) {
                player.runCommand(`effect @s slow_falling 11 1 true`)
                if (player.isJumping) {
                    player.applyKnockback(0, 0, 0, 0.1)
                }
                if (w_aps_hasBoots.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.flight_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasBoots", true)
                }
            }
            else if ((checkFeet == "wonder_aps:wonder_aps_warrior_suit_blue_boots")) {
                player.runCommand(`effect @s slow_falling 11 2 true`)
                if (player.isJumping) {
                    player.applyKnockback(0, 0, 0, 0.8)
                }
                if (w_aps_hasBoots.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.flight_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasBoots", true)
                }
            }
            else if ((checkFeet != "wonder_aps:wonder_aps_nano_suit_boots") || (checkFeet != "wonder_aps:wonder_aps_nano_suit_blue_boots") || (checkFeet != "wonder_aps:wonder_aps_nano_suit_red_boots") || (checkFeet != "wonder_aps:wonder_aps_nano_suit_yellow_boots") || (checkFeet != "wonder_aps:wonder_aps_giga_suit_boots") || (checkFeet != "wonder_aps:wonder_aps_giga_suit_aqua_boots") || (checkFeet != "wonder_aps:wonder_aps_giga_suit_pink_boots") || (checkFeet != "wonder_aps:wonder_aps_giga_suit_purple_boots") || (checkFeet != "wonder_aps:wonder_aps_power_suit_boots") || (checkFeet != "wonder_aps:wonder_aps_power_suit_lime_boots") || (checkFeet != "wonder_aps:wonder_aps_power_suit_orange_boots") || (checkFeet != "wonder_aps:wonder_aps_power_suit_silver_boots") || (checkFeet != "wonder_aps:wonder_aps_super_suit_boots") || (checkFeet != "wonder_aps:wonder_aps_super_suit_tan_boots") || (checkFeet != "wonder_aps:wonder_aps_super_suit_green_boots") || (checkFeet != "wonder_aps:wonder_aps_super_suit_black_boots") || (checkFeet != "wonder_aps:wonder_aps_sun_suit_silver_boots") || (checkFeet != "wonder_aps:wonder_aps_sun_suit_boots") || (checkFeet != "wonder_aps:wonder_aps_sun_suit_bronze_boots") || (checkFeet != "wonder_aps:wonder_aps_sun_suit_red_boots") || (checkFeet != "wonder_aps:wonder_aps_void_suit_boots") || (checkFeet != "wonder_aps:wonder_aps_void_suit_lime_boots") || (checkFeet != "wonder_aps:wonder_aps_void_suit_white_boots") || (checkFeet != "wonder_aps:wonder_aps_void_suit_blue_boots") || (checkFeet != "wonder_aps:wonder_aps_warrior_suit_boots") || (checkFeet != "wonder_aps:wonder_aps_warrior_suit_black_boots") || (checkFeet != "wonder_aps:wonder_aps_warrior_pink_suit_boots") || (checkFeet != "wonder_aps:wonder_aps_warrior_suit_blue_boots")) {
                if (w_aps_hasBoots.toString() === "true") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.flight_off\"}]}`)
                    player.setDynamicProperty("w_aps_hasBoots", false)
                }
            }
        }
        else {
            if (w_aps_hasBoots != undefined) {
                if (w_aps_hasBoots.toString() === "true") {
                    player.setDynamicProperty("w_aps_hasBoots", false)
                }
            }
        }

        // LEGGINGS EFFECTS

        if ((eLegs != undefined) && (w_aps_hasLeggings != undefined)) {
            var checkLegs = eLegs.typeId
            // NANO SUIT
            if ((checkLegs == "wonder_aps:wonder_aps_nano_suit_leggings") || (checkLegs == "wonder_aps:wonder_aps_nano_suit_red_leggings") || (checkLegs == "wonder_aps:wonder_aps_nano_suit_yellow_leggings") || (checkLegs == "wonder_aps:wonder_aps_nano_suit_blue_leggings")) {
                player.runCommand(`effect @s speed 11 1 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            // GIGA SUIT
            else if ((checkLegs == "wonder_aps:wonder_aps_giga_suit_leggings") || (checkLegs == "wonder_aps:wonder_aps_giga_suit_pink_leggings") || (checkLegs == "wonder_aps:wonder_aps_giga_suit_aqua_leggings")) {
                player.runCommand(`effect @s speed 11 8 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            else if ((checkLegs == "wonder_aps:wonder_aps_giga_suit_purple_leggings")) {
                player.runCommand(`effect @s speed 11 10 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            // POWER SUIT
            else if ((checkLegs == "wonder_aps:wonder_aps_power_suit_leggings") || (checkLegs == "wonder_aps:wonder_aps_power_suit_orange_leggings") || (checkLegs == "wonder_aps:wonder_aps_power_suit_lime_leggings")) {
                player.runCommand(`effect @s speed 11 6 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            else if ((checkLegs == "wonder_aps:wonder_aps_power_suit_silver_leggings")) {
                player.runCommand(`effect @s speed 11 1 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            // SUPER SUIT
            else if ((checkLegs == "wonder_aps:wonder_aps_super_suit_leggings") || (checkLegs == "wonder_aps:wonder_aps_super_suit_green_leggings")) {
                player.runCommand(`effect @s speed 11 3 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            else if ((checkLegs == "wonder_aps:wonder_aps_super_suit_tan_leggings") || (checkLegs == "wonder_aps:wonder_aps_super_suit_black_leggings")) {
                player.runCommand(`effect @s speed 11 8 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            // SUN SUIT
            else if ((checkLegs == "wonder_aps:wonder_aps_sun_suit_leggings") || (checkLegs == "wonder_aps:wonder_aps_sun_suit_red_leggings")) {
                player.runCommand(`effect @s speed 11 6 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            else if ((checkLegs == "wonder_aps:wonder_aps_sun_suit_bronze_leggings")) {
                player.runCommand(`effect @s speed 11 3 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            else if ((checkLegs == "wonder_aps:wonder_aps_sun_suit_silver_leggings")) {
                player.runCommand(`effect @s speed 11 1 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            // VOID SUIT
            else if ((checkLegs == "wonder_aps:wonder_aps_void_suit_leggings") || (checkLegs == "wonder_aps:wonder_aps_void_suit_blue_leggings")) {
                player.runCommand(`effect @s speed 11 8 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            else if ((checkLegs == "wonder_aps:wonder_aps_void_suit_white_leggings")) {
                player.runCommand(`effect @s speed 11 2 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            else if ((checkLegs == "wonder_aps:wonder_aps_void_suit_lime_leggings")) {
                player.runCommand(`effect @s speed 11 4 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            // WARRIOR SUIT
            else if ((checkLegs == "wonder_aps:wonder_aps_warrior_suit_leggings") || (checkLegs == "wonder_aps:wonder_aps_warrior_suit_black_leggings")) {
                player.runCommand(`effect @s speed 11 8 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            else if ((checkLegs == "wonder_aps:wonder_aps_warrior_suit_pink_leggings") || (checkLegs == "wonder_aps:wonder_aps_warrior_suit_blue_leggings")) {
                player.runCommand(`effect @s speed 11 9 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            // PROTO SUIT
            else if ((checkLegs == "wonder_aps:wonder_aps_proto_suit_green_leggings") || (checkLegs == "wonder_aps:wonder_aps_proto_suit_black_leggings")) {
                player.runCommand(`effect @s speed 11 1 true`)
                if (w_aps_hasLeggings.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasLeggings", true)
                }
            }
            // DISABLE ALL
            else if ((checkLegs != "wonder_aps:wonder_aps_nano_suit_leggings") || (checkLegs != "wonder_aps:wonder_aps_nano_suit_red_leggings") || (checkLegs != "wonder_aps:wonder_aps_nano_suit_yellow_leggings") || (checkLegs != "wonder_aps:wonder_aps_nano_suit_blue_leggings") || (checkLegs != "wonder_aps:wonder_aps_giga_suit_leggings") || (checkLegs != "wonder_aps:wonder_aps_giga_suit_purple_leggings") || (checkLegs != "wonder_aps:wonder_aps_giga_suit_pink_leggings") || (checkLegs != "wonder_aps:wonder_aps_giga_suit_aqua_leggings") || (checkLegs != "wonder_aps:wonder_aps_power_suit_leggings") || (checkLegs != "wonder_aps:wonder_aps_power_suit_silver_leggings") || (checkLegs != "wonder_aps:wonder_aps_power_suit_orange_leggings") || (checkLegs != "wonder_aps:wonder_aps_power_suit_lime_leggings") || (checkLegs != "wonder_aps:wonder_aps_super_suit_leggings") || (checkLegs != "wonder_aps:wonder_aps_super_suit_tan_leggings") || (checkLegs != "wonder_aps:wonder_aps_super_suit_green_leggings") || (checkLegs != "wonder_aps:wonder_aps_super_suit_black_leggings") || (checkLegs != "wonder_aps:wonder_aps_sun_suit_leggings") || (checkLegs != "wonder_aps:wonder_aps_sun_suit_red_leggings") || (checkLegs != "wonder_aps:wonder_aps_sun_suit_silver_leggings") || (checkLegs != "wonder_aps:wonder_aps_sun_suit_bronze_leggings") || (checkLegs != "wonder_aps:wonder_aps_void_suit_leggings") || (checkLegs != "wonder_aps:wonder_aps_void_suit_blue_leggings") || (checkLegs != "wonder_aps:wonder_aps_void_suit_white_leggings") || (checkLegs != "wonder_aps:wonder_aps_void_suit_lime_leggings") || (checkLegs != "wonder_aps:wonder_aps_warrior_suit_blue_leggings") || (checkLegs != "wonder_aps:wonder_aps_warrior_suit_pink_leggings") || (checkLegs != "wonder_aps:wonder_aps_warrior_suit_black_leggings") || (checkLegs != "wonder_aps:wonder_aps_warrior_suit_leggings") || (checkLegs != "wonder_aps:wonder_aps_proto_suit_leggings") || (checkLegs != "wonder_aps:wonder_aps_proto_suit_silver_leggings") || (checkLegs != "wonder_aps:wonder_aps_proto_suit_black_leggings") || (checkLegs != "wonder_aps:wonder_aps_proto_suit_green_leggings")) {
                if (w_aps_hasLeggings.toString() === "true") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.speed_off\"}]}`)
                    player.setDynamicProperty("w_aps_hasLeggings", false)
                }
            }
        }
        else {
            if (w_aps_hasLeggings != undefined) {
                if (w_aps_hasLeggings.toString() === "true") {
                    player.setDynamicProperty("w_aps_hasLeggings", false)
                }
            }
        }

        // CHESTPLATE EFFECTS

        if ((eChest != undefined) && (w_aps_hasChest != undefined)) {
            var checkChest = eChest.typeId
            // NANO SUIT
            // DEFAULT
            if ((checkChest == "wonder_aps:wonder_aps_nano_suit_chestplate")) {
                player.runCommand(`effect @s haste 11 1 true`)
                player.runCommand(`effect @s strength 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // DEEP-SEA
            else if ((checkChest == "wonder_aps:wonder_aps_nano_suit_blue_chestplate")) {
                player.runCommand(`effect @s haste 11 1 true`)
                player.runCommand(`effect @s strength 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // FLAME
            else if ((checkChest == "wonder_aps:wonder_aps_nano_suit_red_chestplate")) {
                player.runCommand(`effect @s haste 11 1 true`)
                player.runCommand(`effect @s strength 11 3 true`)
                player.runCommand(`effect @s fire_resistance 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // ROYAL
            else if ((checkChest == "wonder_aps:wonder_aps_nano_suit_yellow_chestplate")) {
                player.runCommand(`effect @s haste 11 1 true`)
                player.runCommand(`effect @s strength 11 5 true`)
                player.runCommand(`effect @s resistance 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // SUPER SUIT
            // DEFAULT
            else if ((checkChest == "wonder_aps:wonder_aps_super_suit_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 7 true`)
                player.runCommand(`effect @s regeneration 11 1 true`)
                player.runCommand(`effect @s resistance 11 1 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // TECH SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_super_suit_black_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 10 true`)
                player.runCommand(`effect @s regeneration 11 1 true`)
                player.runCommand(`effect @s resistance 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // NATURE SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_super_suit_green_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 7 true`)
                player.runCommand(`effect @s regeneration 11 1 true`)
                player.runCommand(`effect @s resistance 11 1 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // SAND SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_super_suit_tan_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 7 true`)
                player.runCommand(`effect @s regeneration 11 1 true`)
                player.runCommand(`effect @s resistance 11 1 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // GIGA SUIT (ALL)
            else if ((checkChest == "wonder_aps:wonder_aps_giga_suit_chestplate") || (checkChest == "wonder_aps:wonder_aps_giga_suit_pink_chestplate") || (checkChest == "wonder_aps:wonder_aps_giga_suit_purple_chestplate") || (checkChest == "wonder_aps:wonder_aps_giga_suit_aqua_chestplate")) {
                player.runCommand(`effect @s haste 11 3 true`)
                player.runCommand(`effect @s strength 11 9 true`)
                player.runCommand(`effect @s regeneration 11 4 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // POWER SUIT
            // DEFAULT
            else if ((checkChest == "wonder_aps:wonder_aps_power_suit_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 8 true`)
                player.runCommand(`effect @s regeneration 11 2 true`)
                player.runCommand(`effect @s resistance 11 2 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // TOXIC SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_power_suit_lime_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 8 true`)
                player.runCommand(`effect @s regeneration 11 5 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // TITANIUM SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_power_suit_silver_chestplate")) {
                player.runCommand(`effect @s haste 11 3 true`)
                player.runCommand(`effect @s strength 11 10 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // NETHER SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_power_suit_orange_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 8 true`)
                player.runCommand(`effect @s regeneration 11 2 true`)
                player.runCommand(`effect @s resistance 11 2 true`)
                player.runCommand(`effect @s fire_resistance 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // ALLOY SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_sun_suit_silver_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 10 true`)
                player.runCommand(`effect @s regeneration 11 1 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // BRONZE SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_sun_suit_bronze_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 7 true`)
                player.runCommand(`effect @s regeneration 11 1 true`)
                player.runCommand(`effect @s resistance 11 2 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // SUN SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_sun_suit_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 8 true`)
                player.runCommand(`effect @s regeneration 11 5 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // HERO SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_sun_suit_red_chestplate")) {
                player.runCommand(`effect @s haste 11 1 true`)
                player.runCommand(`effect @s strength 11 6 true`)
                player.runCommand(`effect @s fire_resistance 11 3 true`)
                player.runCommand(`effect @s regeneration 11 5 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // ICE SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_void_suit_blue_chestplate")) {
                player.runCommand(`effect @s haste 11 1 true`)
                player.runCommand(`effect @s strength 11 3 true`)
                player.runCommand(`effect @s resistance 11 1 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // RGB SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_void_suit_white_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 7 true`)
                player.runCommand(`effect @s regeneration 11 1 true`)
                player.runCommand(`effect @s resistance 11 1 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // DEMON SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_void_suit_lime_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 8 true`)
                player.runCommand(`effect @s regeneration 11 2 true`)
                player.runCommand(`effect @s resistance 11 1 true`)
                player.runCommand(`effect @s fire_resistance 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // VOID SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_void_suit_chestplate")) {
                player.runCommand(`effect @s haste 11 1 true`)
                player.runCommand(`effect @s strength 11 5 true`)
                player.runCommand(`effect @s fire_resistance 11 3 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                player.runCommand(`effect @s regeneration 11 5 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // PROTO SUIT
            // DEFAULT
            else if ((checkChest == "wonder_aps:wonder_aps_proto_suit_chestplate")) {
                player.runCommand(`effect @s strength 11 1 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // TRAINING SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_proto_suit_silver_chestplate")) {
                player.runCommand(`effect @s strength 11 2 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // BASIC SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_proto_suit_black_chestplate")) {
                player.runCommand(`effect @s strength 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // STANDARD SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_proto_suit_green_chestplate")) {
                player.runCommand(`effect @s strength 11 3 true`)
                player.runCommand(`effect @s haste 11 1 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // WARRIOR SUIT
            // DEFAULT
            else if ((checkChest == "wonder_aps:wonder_aps_warrior_suit_chestplate")) {
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 7 true`)
                player.runCommand(`effect @s regeneration 11 1 true`)
                player.runCommand(`effect @s resistance 11 2 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // ULTIMATE SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_warrior_suit_black_chestplate")) {
                player.runCommand(`effect @s regeneration 11 2 true`)
                player.runCommand(`effect @s haste 11 2 true`)
                player.runCommand(`effect @s strength 11 8 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                player.runCommand(`effect @s fire_resistance 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // QUANTUM SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_warrior_suit_pink_chestplate")) {
                player.runCommand(`effect @s haste 11 3 true`)
                player.runCommand(`effect @s strength 11 9 true`)
                player.runCommand(`effect @s regeneration 11 4 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            // TANK SUIT
            else if ((checkChest == "wonder_aps:wonder_aps_warrior_suit_blue_chestplate")) {
                player.runCommand(`effect @s haste 11 3 true`)
                player.runCommand(`effect @s strength 11 9 true`)
                player.runCommand(`effect @s regeneration 11 4 true`)
                player.runCommand(`effect @s resistance 11 4 true`)
                player.runCommand(`effect @s fire_resistance 11 3 true`)
                if (w_aps_hasChest.toString() === "false") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_on\"}]}`)
                    player.runCommand(`playsound wonder_aps:armor_on @s`)
                    player.setDynamicProperty("w_aps_hasChest", true)
                }
            }
            else if ((checkChest != "wonder_aps:wonder_aps_nano_suit_chestplate") || (checkChest != "wonder_aps:wonder_aps_nano_suit_red_chestplate") || (checkChest != "wonder_aps:wonder_aps_nano_suit_yellow_chestplate") || (checkChest != "wonder_aps:wonder_aps_nano_suit_blue_chestplate") || (checkChest != "wonder_aps:wonder_aps_giga_suit_chestplate") || (checkChest != "wonder_aps:wonder_aps_giga_suit_pink_chestplate") || (checkChest != "wonder_aps:wonder_aps_giga_suit_purple_chestplate") || (checkChest != "wonder_aps:wonder_aps_giga_suit_aqua_chestplate") || (checkChest != "wonder_aps:wonder_aps_power_suit_chestplate") || (checkChest != "wonder_aps:wonder_aps_power_suit_lime_chestplate") || (checkChest != "wonder_aps:wonder_aps_power_suit_orange_chestplate") || (checkChest != "wonder_aps:wonder_aps_power_suit_silver_chestplate") || (checkChest != "wonder_aps:wonder_aps_super_suit_chestplate") || (checkChest != "wonder_aps:wonder_aps_super_suit_black_chestplate") || (checkChest != "wonder_aps:wonder_aps_super_suit_green_chestplate") || (checkChest != "wonder_aps:wonder_aps_super_suit_tan_chestplate") || (checkChest != "wonder_aps:wonder_aps_sun_suit_chestplate") || (checkChest != "wonder_aps:wonder_aps_sun_suit_red_chestplate") || (checkChest != "wonder_aps:wonder_aps_sun_suit_silver_chestplate") || (checkChest != "wonder_aps:wonder_aps_sun_suit_bronze_chestplate") || (checkChest != "wonder_aps:wonder_aps_void_suit_chestplate") || (checkChest != "wonder_aps:wonder_aps_void_suit_lime_chestplate") || (checkChest != "wonder_aps:wonder_aps_void_suit_white_chestplate") || (checkChest != "wonder_aps:wonder_aps_void_suit_blue_chestplate") || (checkChest != "wonder_aps:wonder_aps_proto_suit_chestplate") || (checkChest != "wonder_aps:wonder_aps_proto_suit_silver_chestplate") || (checkChest != "wonder_aps:wonder_aps_proto_suit_black_chestplate") || (checkChest != "wonder_aps:wonder_aps_proto_suit_green_chestplate") || (checkChest != "wonder_aps:wonder_aps_warrior_suit_chestplate") || (checkChest != "wonder_aps:wonder_aps_warrior_suit_black_chestplate") || (checkChest != "wonder_aps:wonder_aps_warrior_suit_pink_chestplate") || (checkChest != "wonder_aps:wonder_aps_warrior_suit_blue_chestplate")) {
                if (w_aps_hasChest.toString() === "true") {
                    player.runCommand(`titleraw @s actionbar {\"rawtext\":[{\"translate\":\"hint.wonder_aps.strength_off\"}]}`)
                    player.setDynamicProperty("w_aps_hasChest", false)
                }
            }
        }
        else {
            if (w_aps_hasChest != undefined) {
                if (w_aps_hasChest.toString() === "true") {
                    player.setDynamicProperty("w_aps_hasChest", false)
                }
            }
        }
    }
}, 1)

world.afterEvents.itemUse.subscribe((data) => {
    const player = data.source
    const item = data.itemStack
    const cooldown = item.getComponent("minecraft:cooldown")

    if (item.typeId === "wonder_aps:wonder_aps_ability_explosive" && player.getItemCooldown("ability_explosive") === cooldown.cooldownTicks - 1) {
        player.runCommandAsync("playsound wonder_aps:plasma_cube_throw @a[r=50] ~ ~ ~")
    }
    else if (item.typeId === "wonder_aps:wonder_aps_ability_lightning" && player.getItemCooldown("ability_lightning") === cooldown.cooldownTicks - 1) {
        player.runCommandAsync("playsound wonder_aps:lightning_throw @a[r=50] ~ ~ ~")
    }
    else if (item.typeId === "wonder_aps:wonder_aps_ability_insta_heal" && player.getItemCooldown("ability_insta_heal") === cooldown.cooldownTicks - 1) {
        player.runCommandAsync("playsound wonder_aps:insta_heal_use @a[r=50] ~ ~ ~")
        player.runCommandAsync("particle wonder_aps:insta_heal_hearts ~ ~ ~")
        player.runCommandAsync("particle wonder_aps:insta_heal_sparkles ~ ~ ~")
        player.runCommandAsync("effect @s instant_health 1 255 true")
        player.runCommandAsync("effect @s saturation 1 255 true")
    }
    else if (item.typeId === "wonder_aps:wonder_aps_ability_fire" && player.getItemCooldown("ability_fire") === cooldown.cooldownTicks - 1) {
        player.runCommandAsync("playsound wonder_aps:fire_cube_throw @a[r=50] ~ ~ ~")
    }
    else if (item.typeId === "wonder_aps:wonder_aps_ability_dragon" && player.getItemCooldown("ability_dragon") === cooldown.cooldownTicks - 1) {
        player.runCommandAsync("playsound wonder_aps:dragon_throw @a[r=50] ~ ~ ~")
    }

    const location = Vector3Add(player.getHeadLocation(), player.getViewDirection())
    if (item.typeId === "wonder_aps:wonder_aps_flamethrower") {
        const power = 1
        const velocity = Vector3Multiply(player.getViewDirection(), power)
        const entity_projectile = player.dimension.spawnEntity("wonder_aps:wonder_aps_flamethrower_projectile", location)
        const projectile = entity_projectile.getComponent('projectile');
        projectile.shoot(velocity)
        player.runCommandAsync("playsound wonder_aps:flamethrower @a[r=50] ~ ~ ~")
    }
    if (item.typeId === "wonder_aps:wonder_aps_void_ray" && cooldown.getCooldownTicksRemaining(player) == 0) {
        const power = 1
        const velocity = Vector3Multiply(player.getViewDirection(), power)
        const entity_projectile = player.dimension.spawnEntity("wonder_aps:wonder_aps_void_ray_projectile", location)
        const projectile = entity_projectile.getComponent('projectile');
        projectile.shoot(velocity)
        cooldown.startCooldown(player)
        player.runCommandAsync("playsound wonder_aps:void_ray_throw @a[r=50] ~ ~ ~")
    }
    if (item.typeId === "wonder_aps:wonder_aps_sun_ray" && cooldown.getCooldownTicksRemaining(player) == 0) {
        const power = 1
        const velocity = Vector3Multiply(player.getViewDirection(), power)
        const entity_projectile = player.dimension.spawnEntity("wonder_aps:wonder_aps_sun_ray_projectile", location)
        const projectile = entity_projectile.getComponent('projectile');
        projectile.shoot(velocity)
        cooldown.startCooldown(player)
        player.runCommandAsync("playsound wonder_aps:sun_ray_throw @a[r=50] ~ ~ ~")
    }
    if (item.typeId === "wonder_aps:wonder_aps_photon_launcher") {
        const power = 1
        const velocity = Vector3Multiply(player.getViewDirection(), power)
        const entity_projectile = player.dimension.spawnEntity("wonder_aps:wonder_aps_photon_projectile", location)
        const projectile = entity_projectile.getComponent('projectile');
        projectile.shoot(velocity)
        player.runCommandAsync("playsound wonder_aps:photon_launcher_throw @a[r=50] ~ ~ ~")
    }
    if (item.typeId === "wonder_aps:wonder_aps_freeze_ray") {
        const power = 1
        const velocity = Vector3Multiply(player.getViewDirection(), power)
        const entity_projectile = player.dimension.spawnEntity("wonder_aps:wonder_aps_freeze_ray_projectile", location)
        const projectile = entity_projectile.getComponent('projectile');
        projectile.shoot(velocity)
        player.runCommandAsync("playsound wonder_aps:photon_launcher_throw @a[r=50] ~ ~ ~")
    }
    if (item.typeId === "wonder_aps:wonder_aps_gravity_cannon" && cooldown.getCooldownTicksRemaining(player) == 0) {
        const power = 1
        const velocity = Vector3Multiply(player.getViewDirection(), power)
        const entity_projectile = player.dimension.spawnEntity("wonder_aps:wonder_aps_gravity_cannon_projectile", location)
        const projectile = entity_projectile.getComponent('projectile');
        projectile.shoot(velocity)
        cooldown.startCooldown(player)
        player.runCommandAsync("playsound wonder_aps:gravity_cannon_throw @a[r=50] ~ ~ ~")
    }
    if (item.typeId === "wonder_aps:wonder_aps_nano_swarm" && cooldown.getCooldownTicksRemaining(player) == 0) {
        const power = 1
        const velocity = Vector3Multiply(player.getViewDirection(), power)
        const entity_projectile = player.dimension.spawnEntity("wonder_aps:wonder_aps_nano_swarm_projectile", location)
        const projectile = entity_projectile.getComponent('projectile');
        projectile.shoot(velocity)
        cooldown.startCooldown(player)
        player.runCommandAsync("playsound wonder_aps:nano_swarm_throw @a[r=50] ~ ~ ~")
    }
})

world.afterEvents.entitySpawn.subscribe((data) => {
    const { entity } = data
    if (entity.typeId == "wonder_aps:wonder_aps_shuriken_projectile") {
        system.runTimeout(() => {
            if (entity.isValid()) entity.remove()
        }, 20)
    }
    if (entity.typeId == "wonder_aps:wonder_aps_photon_projectile") {
        system.runTimeout(() => {
            if (entity.isValid()) entity.remove()
        }, 80)
    }
})

function Vector3Add(a, b) {
    return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z }
}

function Vector3Multiply(a, b) {
    return { x: a.x * b, y: a.y * b, z: a.z * b }
}