use of com.palmergames.bukkit.towny.tasks.TownClaim in project Towny by ElgarL.
the class TownCommand method parseTownUnclaimCommand.
public static void parseTownUnclaimCommand(Player player, String[] split) {
if (split.length == 1 && split[0].equalsIgnoreCase("?")) {
player.sendMessage(ChatTools.formatTitle("/town unclaim"));
player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town unclaim", "", TownySettings.getLangString("mayor_help_6")));
player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town unclaim", "[circle/rect] [radius]", TownySettings.getLangString("mayor_help_7")));
player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town unclaim", "all", TownySettings.getLangString("mayor_help_8")));
} else {
Resident resident;
Town town;
TownyWorld world;
try {
if (TownyUniverse.isWarTime())
throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
resident = TownyUniverse.getDataSource().getResident(player.getName());
town = resident.getTown();
world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
List<WorldCoord> selection;
if (split.length == 1 && split[0].equalsIgnoreCase("all")) {
new TownClaim(plugin, player, town, null, false, false, false).start();
// townUnclaimAll(town);
} else {
selection = AreaSelectionUtil.selectWorldCoordArea(town, new WorldCoord(world.getName(), Coord.parseCoord(plugin.getCache(player).getLastLocation())), split);
selection = AreaSelectionUtil.filterOwnedBlocks(town, selection);
// Set the area to unclaim
new TownClaim(plugin, player, town, selection, false, false, false).start();
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_abandoned_area"), Arrays.toString(selection.toArray(new WorldCoord[0]))));
}
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
}
}
use of com.palmergames.bukkit.towny.tasks.TownClaim in project Towny by ElgarL.
the class TownCommand method parseTownClaimCommand.
public static void parseTownClaimCommand(Player player, String[] split) {
if (split.length == 1 && split[0].equalsIgnoreCase("?")) {
player.sendMessage(ChatTools.formatTitle("/town claim"));
player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town claim", "", TownySettings.getLangString("msg_block_claim")));
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 (TownyUniverse.isWarTime())
throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
resident = TownyUniverse.getDataSource().getResident(player.getName());
town = resident.getTown();
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, outpost = false;
Coord key = Coord.parseCoord(plugin.getCache(player).getLastLocation());
if (split.length == 1 && split[0].equalsIgnoreCase("outpost")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWN_CLAIM_OUPTPOST.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
int maxOutposts = TownySettings.getMaxResidentOutposts(resident);
if (!TownyUniverse.getPermissionSource().isTownyAdmin(player) && maxOutposts != -1 && (maxOutposts <= resident.getTown().getAllOutpostSpawns().size()))
throw new TownyException(String.format(TownySettings.getLangString("msg_max_outposts_own"), maxOutposts));
if (TownySettings.isAllowingOutposts()) {
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 ((world.getMinDistanceFromOtherTownsPlots(key) < TownySettings.getMinDistanceFromTownPlotblocks()))
throw new TownyException(TownySettings.getLangString("msg_too_close"));
selection = AreaSelectionUtil.selectWorldCoordArea(town, new WorldCoord(world.getName(), key), new String[0]);
blockCost = TownySettings.getOutpostCost();
attachedToEdge = false;
outpost = true;
} else
throw new TownyException(TownySettings.getLangString("msg_outpost_disable"));
} else {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWN_CLAIM_TOWN.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
selection = AreaSelectionUtil.selectWorldCoordArea(town, new WorldCoord(world.getName(), key), split);
blockCost = TownySettings.getClaimPrice();
}
if ((world.getMinDistanceFromOtherTownsPlots(key, town) < TownySettings.getMinDistanceFromTownPlotblocks()))
throw new TownyException(TownySettings.getLangString("msg_too_close"));
TownyMessaging.sendDebugMsg("townClaim: Pre-Filter Selection " + Arrays.toString(selection.toArray(new WorldCoord[0])));
selection = AreaSelectionUtil.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(), TownyEconomyHandler.getFormattedBalance(cost)));
} catch (EconomyException e1) {
throw new TownyException("Economy Error");
}
new TownClaim(plugin, player, town, selection, outpost, true, false).start();
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
}
}
use of com.palmergames.bukkit.towny.tasks.TownClaim in project Towny by ElgarL.
the class TownyAdminCommand method parseAdminUnclaimCommand.
public void parseAdminUnclaimCommand(String[] split) {
if (split.length == 1 && split[0].equalsIgnoreCase("?")) {
for (String line : ta_unclaim) ((CommandSender) getSender()).sendMessage(line);
} else {
if (isConsole) {
sender.sendMessage("[Towny] InputError: This command was designed for use in game only.");
return;
}
try {
if (TownyUniverse.isWarTime())
throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
List<WorldCoord> selection;
selection = AreaSelectionUtil.selectWorldCoordArea(null, new WorldCoord(player.getWorld().getName(), Coord.parseCoord(player)), split);
selection = AreaSelectionUtil.filterWildernessBlocks(selection);
new TownClaim(plugin, player, null, selection, false, false, true).start();
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
}
}
use of com.palmergames.bukkit.towny.tasks.TownClaim in project Towny by ElgarL.
the class TownyWarCustomListener method onCellWonEvent.
@EventHandler(priority = EventPriority.LOWEST)
public void onCellWonEvent(CellWonEvent event) {
CellUnderAttack cell = event.getCellAttackData();
TownyUniverse universe = plugin.getTownyUniverse();
try {
Resident attackingResident = TownyUniverse.getDataSource().getResident(cell.getNameOfFlagOwner());
Town attackingTown = attackingResident.getTown();
Nation attackingNation = attackingTown.getNation();
WorldCoord worldCoord = TownyWar.cellToWorldCoord(cell);
universe.removeWarZone(worldCoord);
TownBlock townBlock = worldCoord.getTownBlock();
Town defendingTown = townBlock.getTown();
// Payments
double amount = 0;
String moneyTranserMsg = null;
if (TownySettings.isUsingEconomy()) {
try {
String reasonType;
if (townBlock.isHomeBlock()) {
amount = TownyWarConfig.getWonHomeblockReward();
reasonType = "Homeblock";
} else {
amount = TownyWarConfig.getWonTownblockReward();
reasonType = "Townblock";
}
if (amount > 0) {
// Defending Town -> Attacker (Pillage)
String reason = String.format("War - Won Enemy %s (Pillage)", reasonType);
amount = Math.min(amount, defendingTown.getHoldingBalance());
defendingTown.payTo(amount, attackingResident, reason);
// Message
moneyTranserMsg = String.format(TownySettings.getLangString("msg_enemy_war_area_won_pillage"), attackingResident.getFormattedName(), TownyEconomyHandler.getFormattedBalance(amount), defendingTown.getFormattedName());
} else if (amount < 0) {
// Attacker -> Defending Town (Rebuild cost)
// Inverse the amount so it's positive.
amount = -amount;
String reason = String.format("War - Won Enemy %s (Rebuild Cost)", reasonType);
if (!attackingResident.payTo(amount, defendingTown, reason)) {
// Could Not Pay Defending Town the Rebuilding Cost.
TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_won"), attackingResident.getFormattedName(), (attackingNation.hasTag() ? attackingNation.getTag() : attackingNation.getFormattedName()), cell.getCellString()));
}
// Message
moneyTranserMsg = String.format(TownySettings.getLangString("msg_enemy_war_area_won_rebuilding"), attackingResident.getFormattedName(), TownyEconomyHandler.getFormattedBalance(amount), defendingTown.getFormattedName());
}
} catch (EconomyException x) {
x.printStackTrace();
}
}
// Defender loses townblock
TownyUniverse.getDataSource().removeTownBlock(townBlock);
// Attacker Claim Automatically
try {
List<WorldCoord> selection = new ArrayList<WorldCoord>();
selection.add(worldCoord);
TownCommand.checkIfSelectionIsValid(attackingTown, selection, false, 0, false);
new TownClaim(plugin, null, attackingTown, selection, false, true, false).start();
} catch (TownyException te) {
// Couldn't claim it.
}
// Cleanup
plugin.updateCache(worldCoord);
// Event Message
TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_won"), attackingResident.getFormattedName(), (attackingNation.hasTag() ? attackingNation.getTag() : attackingNation.getFormattedName()), cell.getCellString()));
// Money Transfer message.
if (TownySettings.isUsingEconomy()) {
if (amount != 0 && moneyTranserMsg != null) {
try {
TownyMessaging.sendResidentMessage(attackingResident, moneyTranserMsg);
} catch (TownyException e) {
}
TownyMessaging.sendTownMessage(defendingTown, moneyTranserMsg);
}
}
} catch (NotRegisteredException e) {
e.printStackTrace();
}
}
Aggregations