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

    if (!player.persistentData.getBoolean('received_starter_items')) {
        // Items
        player.give(Item.of('securitycraft:security_camera', 4))
        player.give(Item.of('securitycraft:camera_monitor', 1))
        player.give(Item.of('minecraft:bread', 16))

        // Grant advancement after short delay
        event.server.scheduleInTicks(20, () => {
            player.server.runCommandSilent(`advancement grant ${player.name} only yourpack:joined_the_horror`)
        })

        player.persistentData.putBoolean('received_starter_items', true)
    }

    // Remove Something Watches book multiple times over 10 seconds
    [40, 80, 120, 200].forEach(ticks => {
        event.server.scheduleInTicks(ticks, () => {
            player.server.runCommandSilent(`clear ${player.name} minecraft:written_book`)
        })
    })
})