if (split.length == 0 || split[0].equalsIgnoreCase("?")) {
for (String line : output)
player.sendMessage(line);
} else {
Resident resident;
TownyWorld world;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
try {
if (split[0].equalsIgnoreCase("claim")) {
if (plugin.getTownyUniverse().isWarTime())
throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
List<WorldCoord> selection = TownyUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.remFirstArg(split));
//selection = TownyUtil.filterUnownedPlots(selection);
if (selection.size() > 0) {
double cost = 0;
// Remove any plots Not for sale (if not the mayor) and tally up costs.
for (WorldCoord worldCoord : new ArrayList<WorldCoord>(selection)) {
try {
double price = worldCoord.getTownBlock().getPlotPrice();
if (price > -1)
cost += worldCoord.getTownBlock().getPlotPrice();
else {
if (!worldCoord.getTownBlock().getTown().isMayor(resident)) // || worldCoord.getTownBlock().getTown().hasAssistant(resident))
selection.remove(worldCoord);
}
} catch (NotRegisteredException e) {
selection.remove(worldCoord);
}
}
int maxPlots = TownySettings.getMaxResidentPlots(resident);
if (maxPlots >= 0 && resident.getTownBlocks().size() + selection.size() > maxPlots)
throw new TownyException(String.format(TownySettings.getLangString("msg_max_plot_own"), maxPlots));
if (TownySettings.isUsingEconomy() && (!resident.canPayFromHoldings(cost)))
throw new TownyException(String.format(TownySettings.getLangString("msg_no_funds_claim"), selection.size(), TownyEconomyObject.getFormattedBalance(cost)));
// Start the claim task
new PlotClaim(plugin, player, resident, selection, PlotClaim.Action.CLAIM).start();
} else {
player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
}
} else if (split[0].equalsIgnoreCase("unclaim")) {
if (plugin.getTownyUniverse().isWarTime())
throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
if (split.length == 2 && split[1].equalsIgnoreCase("all")) {
// Start the unclaim task
new PlotClaim(plugin, player, resident, null, PlotClaim.Action.UNCLAIM).start();
} else {
List<WorldCoord> selection = TownyUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.remFirstArg(split));
selection = TownyUtil.filterOwnedBlocks(resident, selection);
if (selection.size() > 0) {
// Start the unclaim task
new PlotClaim(plugin, player, resident, selection, PlotClaim.Action.UNCLAIM).start();
} else {
player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
}
}
} else if (split[0].equalsIgnoreCase("notforsale") || split[0].equalsIgnoreCase("nfs")) {
List<WorldCoord> selection = TownyUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.remFirstArg(split));
selection = TownyUtil.filterOwnedBlocks(resident.getTown(), selection);
for (WorldCoord worldCoord : selection) {
setPlotForSale(resident, worldCoord, -1);
}
} else if (split[0].equalsIgnoreCase("forsale") || split[0].equalsIgnoreCase("fs")) {
WorldCoord pos = new WorldCoord(world, Coord.parseCoord(player));
double plotPrice = pos.getTownBlock().getTown().getPlotTypePrice(pos.getTownBlock().getType());
if (split.length > 1) {
int areaSelectPivot = TownyUtil.getAreaSelectPivot(split);
List<WorldCoord> selection;
if (areaSelectPivot >= 0) {
selection = TownyUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.subArray(split, areaSelectPivot + 1, split.length));
selection = TownyUtil.filterOwnedBlocks(resident.getTown(), selection);
if (selection.size() == 0) {
player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
return;
}
} else {
selection = new ArrayList<WorldCoord>();
selection.add(pos);
}
// Check that it's not: /plot forsale within rect 3
if (areaSelectPivot != 1) {
try {
// command was 'plot fs $'
plotPrice = Double.parseDouble(split[1]);
if (plotPrice < 0) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
return;
}
} catch (NumberFormatException e) {
throw new TownyException(String.format(TownySettings.getLangString("msg_error_must_be_num")));
}
}
for (WorldCoord worldCoord : selection) {
if (selection.size() > 1)
plotPrice = worldCoord.getTownBlock().getTown().getPlotTypePrice(worldCoord.getTownBlock().getType());
setPlotForSale(resident, worldCoord, plotPrice);
}
} else {
// basic 'plot fs' command
setPlotForSale(resident, pos, plotPrice);
}
} else if (split[0].equalsIgnoreCase("perm")) {
TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
TownyMessaging.sendMessage(player, TownyFormatter.getStatus(townBlock));
} else if (split[0].equalsIgnoreCase("toggle")) {
TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
// Runs tests to make sure we are allowed to work on this plot.
// Ignore the returns as we are only checking for an exception
plotTestOwner(resident, townBlock);
townBlock.getTown();
plotToggle(player, new WorldCoord(world, Coord.parseCoord(player)).getTownBlock(), StringMgmt.remFirstArg(split));
} else if (split[0].equalsIgnoreCase("set")) {
split = StringMgmt.remFirstArg(split);
Town town = resident.getTown();
if (split.length > 0) {
if (split[0].equalsIgnoreCase("perm")) {
//Set plot level permissions (if the plot owner) or Mayor/Assistant of the town.
TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
// Test we are allowed to work on this plot
TownBlockOwner owner = plotTestOwner(resident, townBlock);
town = townBlock.getTown();
// Check we are allowed to set these perms
toggleTest(player, townBlock, StringMgmt.join(StringMgmt.remFirstArg(split), ""));
TownCommand.setTownBlockPermissions(player, owner, townBlock.getPermissions(), StringMgmt.remFirstArg(split), true);
townBlock.setChanged(true);
TownyUniverse.getDataSource().saveTownBlock(townBlock);
return;
}
if ((!TownyUniverse.getPermissionSource().isTownyAdmin(player)) && ((plugin.isPermissions())
&& (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_PLOTTYPE.getNode())))
&& !town.isMayor(resident)
&& !town.hasAssistant(resident))
throw new TownyException(String.format(TownySettings.getLangString("msg_cache_block_error_town_resident"), "change plot types"));
WorldCoord worldCoord = new WorldCoord(world, Coord.parseCoord(player));
TownBlock townBlock = worldCoord.getTownBlock();
setPlotType(resident, worldCoord, split[0]);
townBlock.setChanged(true);
TownyUniverse.getDataSource().saveTownBlock(townBlock);
player.sendMessage(String.format(TownySettings.getLangString("msg_plot_set_type"), split[0]));
} else {
player.sendMessage(ChatTools.formatCommand("", "/plot set", "reset", ""));
player.sendMessage(ChatTools.formatCommand("", "/plot set", "shop|embassy|arena|wilds|spleef", ""));
player.sendMessage(ChatTools.formatCommand("", "/plot set perm", "?", ""));
}
} else if (split[0].equalsIgnoreCase("clear")) {
if (!resident.isMayor())
throw new TownyException(TownySettings.getLangString("msg_not_mayor"));
TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
if (townBlock != null) {
if (townBlock.isOwner(resident.getTown()) && (!townBlock.hasResident())) {
for (String material : world.getPlotManagementMayorDelete())
if (Material.matchMaterial(material) != null) {
plugin.getTownyUniverse().deleteTownBlockMaterial(townBlock, Material.getMaterial(material).getId());
player.sendMessage(String.format(TownySettings.getLangString("msg_clear_plot_material"), material));
} else
throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_property"), material));