Check for being adjacent to a door before attempting to closing it.

Fixes #6301