//Priority: 3
/**

  █▀▄▀█ █▀█ █▄░█ █░█ █▀▄▀█ █▀▀ █▄░█ ▀█▀ ▄▀█ █░░   █▀▀ ▀▄▀ █▀█ █▀▀ █▀█ █ █▀▀ █▄░█ █▀▀ █▀▀
  █░▀░█ █▄█ █░▀█ █▄█ █░▀░█ ██▄ █░▀█ ░█░ █▀█ █▄▄   ██▄ █░█ █▀▀ ██▄ █▀▄ █ ██▄ █░▀█ █▄▄ ██▄

  ☻/  * @file Starting Kit script for give Player starting items on first login
  /▌  * @copyright KnightDexx's Modded Minecraft World & ModernGamingWorld
  /\

*/
PlayerEvents.loggedIn(event => {
    const player = event.player

    // Only run if the player hasn't received the starter kit yet
    if (!player.stages.has('starting_items')) {

        // Mark stage immediately
        player.stages.add('starting_items')

        // Main starter items after 1 tick (inventory ready)
        event.server.schedule(1, () => {

            // === Equip armor & shield ===
            player.setHeadArmorItem(Item.of('minecraft:leather_helmet'))
            player.setChestArmorItem(Item.of('minecraft:leather_chestplate'))
            player.setLegsArmorItem(Item.of('minecraft:leather_leggings'))
            player.setFeetArmorItem(Item.of('minecraft:leather_boots'))
            player.setOffHandItem(Item.of('minecraft:shield'))

            // === Default starter items ===
            const defaultKit = [
                Item.of('minecraft:oak_sapling', 4),
                Item.of('minecraft:iron_sword'),
                Item.of('minecraft:iron_pickaxe'),
                Item.of('minecraft:iron_shovel'),
                Item.of('minecraft:iron_axe'),
                Item.of('constructionwand:iron_wand'),
                Item.of('naturescompass:naturescompass'),
                Item.of('prefab:item_house_improved'),
                Item.of('prefab:item_farm_improved'),
                Item.of('minecraft:cookie', 4),
                Item.of('comforts:sleeping_bag_light_blue'),
                Item.of('minecraft:crafting_table')
            ]

            defaultKit.forEach(item => player.give(item))

            // === Give Eccentric Tome safely ===
            if (Platform.isLoaded('eccentrictome')) {
                const modBooks = {
                    alexsmobs: { "0": { Count: 1, id: "alexsmobs:animal_dictionary" } },
                    apotheosis: { "0": { Count: 1, id: "patchouli:guide_book", tag: { "patchouli:book": "apotheosis:apoth_chronicle" } } },
                    ars_nouveau: { "0": { Count: 1, id: "ars_nouveau:worn_notebook" } },
                    botania: { "0": { Count: 1, id: "botania:lexicon" } },
                    croptopia: { "0": { Count: 1, id: "croptopia:guide" } },
                    enigmaticlegacy: { "0": { Count: 1, id: "enigmaticlegacy:the_acknowledgment" } },
                    extendedcrafting: { "0": { Count: 1, id: "patchouli:guide_book", tag: { "patchouli:book": "extendedcrafting:guide" } } },
                    ftbquests: { "0": { Count: 1, id: "ftbquests:book" } },
                    immersiveengineering: { "0": { Count: 1, id: "immersiveengineering:manual" } },
                    industrialforegoing: { "0": { Count: 1, id: "patchouli:guide_book", tag: { "patchouli:book": "industrialforegoing:industrial_foregoing" } } },
                    mysticalagriculture: { "0": { Count: 1, id: "patchouli:guide_book", tag: { "patchouli:book": "mysticalagriculture:guide" } } },
                    naturesaura: { "0": { Count: 1, id: "patchouli:guide_book", tag: { "patchouli:book": "naturesaura:book" } } },
                    rftoolsbase: { "0": { Count: 1, id: "rftoolsbase:manual" } },
                    sebastrnlib: { "0": { Count: 1, id: "patchouli:guide_book", tag: { "patchouli:book": "sebastrn_mods_guide_book" } } },
                    securitycraft: { "0": { Count: 1, id: "securitycraft:sc_manual" } },
                    thermal: { "0": { Count: 1, id: "patchouli:guide_book", tag: { "patchouli:book": "thermal:guidebook" } } }
                }

                player.give(Item.of('eccentrictome:tome', { 'eccentrictome:mods': modBooks, 'eccentrictome:version': 1.0 }))
            }
        })

        // Backpack after 2 ticks (inventory fully initialized)
        event.server.schedule(2, () => {
            if (Platform.isLoaded('sophisticatedbackpacks')) {
                player.give(Item.of('sophisticatedbackpacks:backpack'))
            }
        })
    }
})
