The J1772 plug has five pins: Two for power, ground, pilot signal, and interlock. The interlock pin is wired to a bit of circuitry in the plug. The car checks for this circuit and won't come out of park if it is present.
Additionally, the pilot signal is what tells the car the amount of available amperage, since that's something the car cannot sense, like voltage. I won't bother to go through all of the details of the handshake, but this piece of information is provided by the duty cycle of the 1Khz square wave pilot signal, with 50% indicating 30A available. Not only does this let the car know what power is available so it won't try and draw too much, the amount of power can change over time (when there is, say, a power shortage) and the car responds accordingly.
The plug is also designed so that the signal pins disengage before the power pins, so both ends can sense the impending disconnect and stop the flow of power, preventing arcing.
The plug is also designed to be safe to use in wet conditions. There's also a ground fault detector.
With the exception of the ground fault, which I haven't tried to test for obvious reasons, I can attest to the fact that all of this works flawlessly on the Leaf. The situation with the Tesla Model S is more complex since there's an adapter involved and I haven't been willing to play with it to see what happens, but if anything it should be harder to move the Tesla in park since the emergency break engages automatically.
EVs used to be a big hacked up mess but that time is long since past.