Hey @nnpa, you are maybe thinking way to complicated.
The following is out of my head. This might be an approach how to get what you want:
float angles = new float;
cam.getRotation().toAngles(angles); // we get the cam angles here
angles = 0; // you don't want to rotate along the x-axis, so we set it to 0
angles = 0; // you don't want to rotate along the z-axis, so we set it to 0
player.setLocalRotation(player.getLocalRotation().fromAngles(angles)); // apply new player rot