EntityEvents.spawned(event => {
    const { entity, level, server } = event;
    if (!entity || !level || !server || level.isClientSide()) return;

    if (String(entity.type) === 'stalker:stalker') {
        let player = level.getNearestPlayer(entity.x, entity.y, entity.z, 40.0, false);
        
        if (player) {
            let mainHand = String(player.getMainHandItem().id);
            let offHand = String(player.getOffHandItem().id);
            let monitorID = 'securitycraft:camera_monitor';

            if (mainHand === monitorID || offHand === monitorID) {
                let username = player.username.getString();
                
                server.runCommandSilent(`effect give ${username} minecraft:blindness 3 0 true`);
                server.runCommandSilent(`effect give ${username} minecraft:darkness 2 0 true`);
                server.runCommandSilent(`playsound minecraft:block.conduit.deactivate ambient ${username} ~ ~ ~ 1.5 0.5`);
                
                player.displayClientMessage(Component.red("WARNING: CAMERA FEED SENSOR INTERFERENCE DETECTED"), true);
            }
        }
    }
});
