sender.sendMessage(ChatTools.formatCommand("Eg", "/townyadmin set mayor", "[town] " + TownySettings.getLangString("town_help_2"), ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/townyadmin set mayor", "[town] npc", ""));
} else
try {
Resident newMayor = null;
Town town = TownyUniverse.getDataSource().getTown(split[1]);
if (split[2].equalsIgnoreCase("npc")) {
String name = nextNpcName();
TownyUniverse.getDataSource().newResident(name);
newMayor = TownyUniverse.getDataSource().getResident(name);
newMayor.setRegistered(System.currentTimeMillis());
newMayor.setLastOnline(0);
newMayor.setNPC(true);
TownyUniverse.getDataSource().saveResident(newMayor);
TownyUniverse.getDataSource().saveResidentList();
// set for no upkeep as an NPC mayor is assigned
town.setHasUpkeep(false);
} else {
newMayor = TownyUniverse.getDataSource().getResident(split[2]);
//set upkeep again
town.setHasUpkeep(true);
}
if (!town.hasResident(newMayor))
TownCommand.townAddResident(town, newMayor);
// Delete the resident if the old mayor was an NPC.
Resident oldMayor = town.getMayor();
town.setMayor(newMayor);
if (oldMayor.isNPC()) {
try {
town.removeResident(oldMayor);
TownyUniverse.getDataSource().removeResident(oldMayor);
TownyUniverse.getDataSource().removeResidentList(oldMayor);
} catch (EmptyTownException e) {