player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town claim", "outpost", TownySettings.getLangString("mayor_help_3")));
player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town claim", "[circle/rect] [radius]", TownySettings.getLangString("mayor_help_4")));
player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town claim", "[circle/rect] auto", TownySettings.getLangString("mayor_help_5")));
} else {
Resident resident;
Town town;
TownyWorld world;
try {
if (plugin.getTownyUniverse().isWarTime())
throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
if (!TownyUniverse.getPermissionSource().isTownyAdmin(player) && plugin.isPermissions() && !TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_CLAIM.getNode()))
throw new TownyException(TownySettings.getLangString("msg_no_perms_claim"));
resident = TownyUniverse.getDataSource().getResident(player.getName());
town = resident.getTown();
if (!resident.isMayor() && !town.hasAssistant(resident))
throw new TownyException(TownySettings.getLangString("msg_not_mayor_ass"));
world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
if (!world.isUsingTowny())
throw new TownyException(TownySettings.getLangString("msg_set_use_towny_off"));
double blockCost = 0;
List<WorldCoord> selection;
boolean attachedToEdge = true;
Coord key = Coord.parseCoord(plugin.getCache(player).getLastLocation());
if (split.length == 1 && split[0].equalsIgnoreCase("outpost")) {
if ((TownySettings.isAllowingOutposts())
&& (!plugin.isPermissions() || ((plugin.isPermissions()) && TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_CLAIM_OUTPOST.getNode())))){
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"));
selection = new ArrayList<WorldCoord>();
selection.add(new WorldCoord(world, key));
blockCost = TownySettings.getOutpostCost();
attachedToEdge = false;
} else
throw new TownyException(TownySettings.getLangString("msg_outpost_disable"));
} else {
selection = TownyUtil.selectWorldCoordArea(town, new WorldCoord(world, key), split);
blockCost = TownySettings.getClaimPrice();
}
TownyMessaging.sendDebugMsg("townClaim: Pre-Filter Selection " + Arrays.toString(selection.toArray(new WorldCoord[0])));
selection = TownyUtil.filterTownOwnedBlocks(selection);
TownyMessaging.sendDebugMsg("townClaim: Post-Filter Selection " + Arrays.toString(selection.toArray(new WorldCoord[0])));
checkIfSelectionIsValid(town, selection, attachedToEdge, blockCost, false);
try {
double cost = blockCost * selection.size();
if (TownySettings.isUsingEconomy() && !town.pay(cost, String.format("Town Claim (%d)", selection.size())))
throw new TownyException(String.format(TownySettings.getLangString("msg_no_funds_claim"), selection.size(), cost + TownyEconomyObject.getEconomyCurrency()));
} catch (EconomyException e1) {
throw new TownyException("Economy Error");
}