It's a dirty little secret, well not much of a secret at all really, but the impact the players can have on a setting can be rather extreme. With rare experience every bit of work a DM does in developing a campaign should keep in mind the exp, gp hungry machine that is the Player Character. If one doesn't plan a campaign with the abilities and goals of the PCs in mind they will break it and reshape it unless they are really piss-poor game players or willing participants on a story-land railroading.
Look at little old Middle-Earth the story would unfold a heck of a lot different if there were competent and ruthless D&D adventurers involved. Saruman razing the shire, never would happen. The PCs would beat him to it; how would a band of eager treasure seekers avoid pillaging the shire it's full of cabbages, booze and slaves? Minas Tirith is threatened by an army of wimpy orcs...hmm doesn't seem they would be all that able to keep a band of PCs from pillaging the royal treasury and getting the heck out of dodge does it? Oh the Gandalf died fighting the Balrog and they both pitched into darkness, so the balrog is dead is it? "Time to go pillaging Moria, and by the way hand over that ring."
Unless the PCs are strapped to the railroad they aren't going to play nice and calmly walk the ring to the crack of doom while fighting the war of the ring.
One way DMs will try to preserve setting against the ravages of the PC is to install a lot of high level characters and warriors all over the place to keep the PCs in check. This is an awful solution as it leaves one wondering why the heck the PCs do anything at all, why are the treasures,monsters and villains left for the PCs to deal with? It'll never work the players will either filled hemmed in with few options or will bide their time to strike and pillage the campaign once they are high enough level to do so since it's full of a bunch of lazy do nothing NPCs just waiting to get robbed.
So how's a DM supposed to protect the perfect places and the Mary Sues? By making them actually important to the PCs of course. Do not make the authorities and society a barrier to PC advancement make society and those in power an obvious path to more power for the PCs. Being able to get an army to attack Lord Evils tower by being on good terms with the king or by marrying his not so good looking sister relieves the need of having to kick the kings ass, pillage his treasury and raise an army of mercenaries to go fight Lord Evil.
One method is to have some sort of formal training rule that forces the PCs to interact with some NPCs in a non-violent fashion to gain levels. Players often hate the heck out of this because it "slows down the action"....too bad for them. Training enforces the players need to have a stable society with people and institutions where they can get training. Sure people can self-train but that should take even longer and make life harder on PCs. This method can also pump a lot of cash out of the PC coffers as well, just changing the traditional method of 1 gp = 1 exp to 1gp spent on training = 1 exp is going to impact the campaign and enforce a training rule.
NPCs have families and want to see them in comfort and at least alive. So why should that matter to the PC? Because hirelings and henchmen have families and in the main will be acting to ensure their prosperity and safety and not just be an extra sword arm or an extra backpack of gold on the hoof for the PC. this of course requires one to have a group of players that recognize henchmen and hirelings are valuable and necessary for their PCs and it's part of the DMs job to make sure the players know this and the easiest oldest most reliable method is encumbrance and related fatigue. Carrying six weeks of rations, platemail, two shields, three weapons, 100 arrows and 24,000 g.p. around on ones own back just isn't going to happen, one must employ someone to help and that someone should have someone else they care about.
If the players are the typical roaming and pillaging freak-show the local blacksmith will be closed up tight before the PCs get there, the jeweler will be hiding his wares and the merchant who can't get out of town fast enough will have lots of luxury goods at high prices for sale and make quick deals before he goes away on important business. The NPC merchants and artisans want to deal with gentlemen and those in power not the scariest meanest dudes this side of the great wall of monster land; yes money talks but berserker were-wolves, necromancer assassins and hell-blade wielding self proclaimed princes of some domain no one has ever heard of aren't healthy to do business with. Again this comes back to the NPCs giving a darn about themselves and someone else, the motivation of an artisan or merchant isn't' just to remove gp from a PC but to survive to be in business for a long time. The PC has to be part of things at some level to be able to do regular business.
Make the PC (and player) need and care about the campaign setting by making sure the PC needs more then the g.p. and exp held within. A player should learn to value safety, a good clean well lit place to rest and relax, allies and somewhere to spend all those gp for a PC.