There is no such code I'm not aware of, however any there arebeing any "infrastructure targeting" code in Minecraft.
The situations you describe however, seem to have three possible answersexplanations:
The random number generator hates you.The random number generator hates you. This is a known phenomenon dating all the way back to early dice games. simplySimply put:, the random number generator will seemappears to actively attemptwork to destroy you. Solution: Other than Short of making a shrine to the RNG gods none, no solution to this problem is known.
Selective memory.Selective memory. You are simply remembering the worst times you gotwere horribly griefed, and not more vividly than the times creepersmobs spawned way out in the open sowhere you could easily take them on easily, even if they are equally common.
Death from above. The first two situations you gave sound like you were in an enclosed, partially lit cave. this increasesThis type of environment would increase the spawn chance in other nearby areas. asIn such a scenario, mobs using the "Death from above" routineAbove" tactics is commonfor more likely, especially in abandoned mineshaftsmine-shafts. the endermanThe Enderman case you describe just sounds like bad luck (or see numberSee point 1).