public void newTown(Player player, String name, String mayorName) {
TownyUniverse universe = plugin.getTownyUniverse();
try {
if (universe.isWarTime())
throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
if (!TownyUniverse.getPermissionSource().isTownyAdmin(player) && ((TownySettings.isTownCreationAdminOnly() && !plugin.isPermissions())
|| (plugin.isPermissions() && !TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_NEW.getNode()))))
throw new TownyException(TownySettings.getNotPermToNewTownLine());
if (TownySettings.hasTownLimit() && TownyUniverse.getDataSource().getTowns().size() >= TownySettings.getTownLimit())
throw new TownyException(TownySettings.getLangString("msg_err_universe_limit"));
if (!TownySettings.isValidRegionName(name))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_name"), name));
Resident resident = TownyUniverse.getDataSource().getResident(mayorName);
if (resident.hasTown())
throw new TownyException(String.format(TownySettings.getLangString("msg_err_already_res"), resident.getName()));
TownyWorld world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
if (!world.isUsingTowny())
throw new TownyException(TownySettings.getLangString("msg_set_use_towny_off"));
Coord key = Coord.parseCoord(player);
if (world.hasTownBlock(key))
throw new TownyException(String.format(TownySettings.getLangString("msg_already_claimed_1"), key));
if (world.getMinDistanceFromOtherTowns(key) < TownySettings.getMinDistanceFromTownHomeblocks())
throw new TownyException(TownySettings.getLangString("msg_too_close"));
if (TownySettings.getMaxDistanceBetweenHomeblocks() > 0)
if ((world.getMinDistanceFromOtherTowns(key) > TownySettings.getMaxDistanceBetweenHomeblocks()) && world.hasTowns())
throw new TownyException(TownySettings.getLangString("msg_too_far"));
if (TownySettings.isUsingEconomy() && !resident.pay(TownySettings.getNewTownPrice(), "New Town Cost"))
throw new TownyException(String.format(TownySettings.getLangString("msg_no_funds_new_town"), (resident.getName().equals(player.getName()) ? "You" : resident.getName())));
newTown(universe, world, name, resident, key, player.getLocation());
TownyMessaging.sendGlobalMessage(TownySettings.getNewTownMsg(player.getName(), name));
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());