That looks like a huge load of checks for each player while undocking/docking. Probably add an cooldown for docking/undocking just like jump gates have then to prevent spam? As we all know, you can easily disable the RP video massively cutting down the undock/dock time and just spam it all over the place.
Not quite sure how those checks will impact server performance but it doesn't look like an inline statement to me. You are not going to tell me that you are looping through all ships, do you lol? Just wondering.