GLAMER - II. Multiple-plane gravitational lensing