use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class PlotCommand method parsePlotCommand.
public boolean parsePlotCommand(Player player, String[] split) throws TownyException {
if (split.length == 0 || split[0].equalsIgnoreCase("?")) {
for (String line : output) player.sendMessage(line);
} else {
Resident resident;
String world;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
world = player.getWorld().getName();
// resident.getTown();
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return true;
}
try {
if (split[0].equalsIgnoreCase("claim")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_PLOT_CLAIM.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (TownyUniverse.isWarTime())
throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
List<WorldCoord> selection = AreaSelectionUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.remFirstArg(split));
if (selection.size() > 0) {
double cost = 0;
// 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(), TownyEconomyHandler.getFormattedBalance(cost)));
// Start the claim task
new PlotClaim(plugin, player, resident, selection, true).start();
} else {
player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
}
} else if (split[0].equalsIgnoreCase("unclaim")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_PLOT_UNCLAIM.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (TownyUniverse.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, false).start();
} else {
List<WorldCoord> selection = AreaSelectionUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.remFirstArg(split));
selection = AreaSelectionUtil.filterOwnedBlocks(resident, selection);
if (selection.size() > 0) {
// Start the unclaim task
new PlotClaim(plugin, player, resident, selection, false).start();
} else {
player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
}
}
} else if (split[0].equalsIgnoreCase("notforsale") || split[0].equalsIgnoreCase("nfs")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_PLOT_NOTFORSALE.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
List<WorldCoord> selection = AreaSelectionUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.remFirstArg(split));
selection = AreaSelectionUtil.filterOwnedBlocks(resident.getTown(), selection);
for (WorldCoord worldCoord : selection) {
setPlotForSale(resident, worldCoord, -1);
}
} else if (split[0].equalsIgnoreCase("forsale") || split[0].equalsIgnoreCase("fs")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_PLOT_FORSALE.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
WorldCoord pos = new WorldCoord(world, Coord.parseCoord(player));
double plotPrice = pos.getTownBlock().getTown().getPlotTypePrice(pos.getTownBlock().getType());
if (split.length > 1) {
int areaSelectPivot = AreaSelectionUtil.getAreaSelectPivot(split);
List<WorldCoord> selection;
if (areaSelectPivot >= 0) {
selection = AreaSelectionUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.subArray(split, areaSelectPivot + 1, split.length));
selection = AreaSelectionUtil.filterOwnedBlocks(resident.getTown(), selection);
if (selection.size() == 0) {
player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
return true;
}
} 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 true;
}
} catch (NumberFormatException e) {
player.sendMessage(String.format(TownySettings.getLangString("msg_error_must_be_num")));
return true;
}
}
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")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_PLOT_PERM.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
TownyMessaging.sendMessage(player, TownyFormatter.getStatus(townBlock));
} else if (split[0].equalsIgnoreCase("toggle")) {
/*
* perm test in the plottoggle.
*/
TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
// Test we are allowed to work on this plot
// ignore the return as
plotTestOwner(resident, townBlock);
// we are only checking
// for an exception
plotToggle(player, new WorldCoord(world, Coord.parseCoord(player)).getTownBlock(), StringMgmt.remFirstArg(split));
} else if (split[0].equalsIgnoreCase("set")) {
split = StringMgmt.remFirstArg(split);
if (split.length > 0) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_PLOT_SET.getNode(split[0].toLowerCase())))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
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);
// Check we are allowed to set these perms
toggleTest(player, townBlock, StringMgmt.join(StringMgmt.remFirstArg(split), ""));
setTownBlockPermissions(player, owner, townBlock, StringMgmt.remFirstArg(split));
return true;
} else if (split[0].equalsIgnoreCase("name")) {
TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
// Test we are allowed to work on this plot
plotTestOwner(resident, townBlock);
if (split.length == 1) {
townBlock.setName("");
TownyMessaging.sendMsg(player, String.format("Plot name removed"));
TownyUniverse.getDataSource().saveTownBlock(townBlock);
return true;
}
// Test if the plot name contains invalid characters.
if (!NameValidation.isBlacklistName(split[1])) {
townBlock.setName(StringMgmt.join(StringMgmt.remFirstArg(split), ""));
// townBlock.setChanged(true);
TownyUniverse.getDataSource().saveTownBlock(townBlock);
TownyMessaging.sendMsg(player, String.format("Plot name set to [%s]", townBlock.getName()));
} else {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
}
return true;
}
WorldCoord worldCoord = new WorldCoord(world, Coord.parseCoord(player));
setPlotType(resident, worldCoord, split[0]);
player.sendMessage(String.format(TownySettings.getLangString("msg_plot_set_type"), split[0]));
} else {
player.sendMessage(ChatTools.formatCommand("", "/plot set", "name", ""));
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 (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_PLOT_CLEAR.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
if (townBlock != null) {
/**
* Only allow mayors or plot owners to use this command.
*/
if (townBlock.hasResident()) {
if (!townBlock.isOwner(resident)) {
player.sendMessage(TownySettings.getLangString("msg_area_not_own"));
return true;
}
} else if (!townBlock.getTown().equals(resident.getTown())) {
player.sendMessage(TownySettings.getLangString("msg_area_not_own"));
return true;
}
for (String material : TownyUniverse.getDataSource().getWorld(world).getPlotManagementMayorDelete()) if (Material.matchMaterial(material) != null) {
TownyRegenAPI.deleteTownBlockMaterial(townBlock, Material.getMaterial(material));
player.sendMessage(String.format(TownySettings.getLangString("msg_clear_plot_material"), material));
} else
throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_property"), material));
// Raise an event for the claim
BukkitTools.getPluginManager().callEvent(new PlotClearEvent(townBlock));
} else {
// Shouldn't ever reach here as a null townBlock should
// be caught already in WorldCoord.
player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
}
} else
throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_property"), split[0]));
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
} catch (EconomyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
return true;
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class PlotCommand method setPlotForSale.
/**
* Set the plot for sale/not for sale if permitted
*
* @param resident
* @param worldCoord
* @param forSale
* @throws TownyException
*/
public void setPlotForSale(Resident resident, WorldCoord worldCoord, double forSale) throws TownyException {
if (resident.hasTown())
try {
TownBlock townBlock = worldCoord.getTownBlock();
// Test we are allowed to work on this plot
// ignore the return as we
plotTestOwner(resident, townBlock);
// exception
if (forSale > 1000000) {
TownyUniverse.getPlayer(resident).sendMessage("Plot price too expensive.");
} else {
townBlock.setPlotPrice(forSale);
if (forSale != -1)
TownyMessaging.sendTownMessage(townBlock.getTown(), TownySettings.getPlotForSaleMsg(resident.getName(), worldCoord));
else
TownyUniverse.getPlayer(resident).sendMessage(TownySettings.getLangString("msg_err_plot_nfs"));
// Save this townblock so the for sale status is remembered.
TownyUniverse.getDataSource().saveTownBlock(townBlock);
}
} catch (NotRegisteredException e) {
throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
}
else
throw new TownyException(TownySettings.getLangString("msg_err_must_belong_town"));
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class PlotCommand method toggleTest.
/**
* Check the world and town settings to see if we are allowed to alter these
* settings
*
* @param player
* @param townBlock
* @param split
* @throws TownyException if toggle is not permitted
*/
private void toggleTest(Player player, TownBlock townBlock, String split) throws TownyException {
// Make sure we are allowed to set these permissions.
Town town = townBlock.getTown();
split = split.toLowerCase();
if (split.contains("mobs")) {
if (town.getWorld().isForceTownMobs())
throw new TownyException(TownySettings.getLangString("msg_world_mobs"));
}
if (split.contains("fire")) {
if (town.getWorld().isForceFire())
throw new TownyException(TownySettings.getLangString("msg_world_fire"));
}
if (split.contains("explosion")) {
if (town.getWorld().isForceExpl())
throw new TownyException(TownySettings.getLangString("msg_world_expl"));
}
if (split.contains("pvp")) {
if (town.getWorld().isForcePVP())
throw new TownyException(TownySettings.getLangString("msg_world_pvp"));
}
if ((split.contains("pvp")) || (split.trim().equalsIgnoreCase("off"))) {
if (townBlock.getType().equals(TownBlockType.ARENA))
throw new TownyException(TownySettings.getLangString("msg_plot_pvp"));
}
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class TownyAdminCommand method nextNpcName.
public String nextNpcName() throws TownyException {
String name;
int i = 0;
do {
name = TownySettings.getNPCPrefix() + ++i;
if (!TownyUniverse.getDataSource().hasResident(name))
return name;
if (i > 100000)
throw new TownyException(TownySettings.getLangString("msg_err_too_many_npc"));
} while (true);
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class TownyWorldCommand method worldToggle.
public void worldToggle(Player player, CommandSender sender, String[] split) throws TownyException {
if (split.length == 0) {
player.sendMessage(ChatTools.formatTitle("/TownyWorld toggle"));
player.sendMessage(ChatTools.formatCommand("", "/TownyWorld toggle", "claimable", ""));
player.sendMessage(ChatTools.formatCommand("", "/TownyWorld toggle", "usingtowny", ""));
player.sendMessage(ChatTools.formatCommand("", "/TownyWorld toggle", "pvp/forcepvp", ""));
player.sendMessage(ChatTools.formatCommand("", "/TownyWorld toggle", "explosion/forceexplosion", ""));
player.sendMessage(ChatTools.formatCommand("", "/TownyWorld toggle", "fire/forcefire", ""));
player.sendMessage(ChatTools.formatCommand("", "/TownyWorld toggle", "townmobs/worldmobs", ""));
player.sendMessage(ChatTools.formatCommand("", "/TownyWorld toggle", "revertunclaim/revertexpl", ""));
} else {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNYWORLD_TOGGLE.getNode(split[0].toLowerCase())))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
String msg;
if (split[0].equalsIgnoreCase("claimable")) {
Globalworld.setClaimable(!Globalworld.isClaimable());
msg = String.format(TownySettings.getLangString("msg_set_claim"), Globalworld.getName(), Globalworld.isClaimable() ? "Enabled" : "Disabled");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("usingtowny")) {
Globalworld.setUsingTowny(!Globalworld.isUsingTowny());
plugin.resetCache();
msg = String.format(Globalworld.isUsingTowny() ? TownySettings.getLangString("msg_set_use_towny_on") : TownySettings.getLangString("msg_set_use_towny_off"));
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("pvp")) {
Globalworld.setPVP(!Globalworld.isPVP());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "Global PVP", Globalworld.getName(), Globalworld.isPVP() ? "Enabled" : "Disabled");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("forcepvp")) {
Globalworld.setForcePVP(!Globalworld.isForcePVP());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "Force town PVP", Globalworld.getName(), Globalworld.isForcePVP() ? "Forced" : "Adjustable");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("explosion")) {
Globalworld.setExpl(!Globalworld.isExpl());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "Explosions", Globalworld.getName(), Globalworld.isExpl() ? "Enabled" : "Disabled");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("forceexplosion")) {
Globalworld.setForceExpl(!Globalworld.isForceExpl());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "Force town Explosions", Globalworld.getName(), Globalworld.isForceExpl() ? "Forced" : "Adjustable");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("fire")) {
Globalworld.setFire(!Globalworld.isFire());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "Fire Spread", Globalworld.getName(), Globalworld.isFire() ? "enabled" : "disabled");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("forcefire")) {
Globalworld.setForceFire(!Globalworld.isForceFire());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "Force town Fire Spread", Globalworld.getName(), Globalworld.isForceFire() ? "Forced" : "Adjustable");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("townmobs")) {
Globalworld.setForceTownMobs(!Globalworld.isForceTownMobs());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "Town Mob spawns", Globalworld.getName(), Globalworld.isForceTownMobs() ? "Forced" : "Adjustable");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("worldmobs")) {
Globalworld.setWorldMobs(!Globalworld.hasWorldMobs());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "World Mob spawns", Globalworld.getName(), Globalworld.hasWorldMobs() ? "Enabled" : "Disabled");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("revertunclaim")) {
Globalworld.setUsingPlotManagementRevert(!Globalworld.isUsingPlotManagementRevert());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "Unclaim Revert", Globalworld.getName(), Globalworld.isUsingPlotManagementRevert() ? "Enabled" : "Disabled");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else if (split[0].equalsIgnoreCase("revertexpl")) {
Globalworld.setUsingPlotManagementWildRevert(!Globalworld.isUsingPlotManagementWildRevert());
msg = String.format(TownySettings.getLangString("msg_changed_world_setting"), "Wilderness Explosion Revert", Globalworld.getName(), Globalworld.isUsingPlotManagementWildRevert() ? "Enabled" : "Disabled");
if (player != null)
TownyMessaging.sendMsg(player, msg);
else
TownyMessaging.sendMsg(msg);
} else {
msg = String.format(TownySettings.getLangString("msg_err_invalid_property"), "'" + split[0] + "'");
if (player != null)
TownyMessaging.sendErrorMsg(player, msg);
else
TownyMessaging.sendErrorMsg(msg);
return;
}
TownyUniverse.getDataSource().saveWorld(Globalworld);
}
}
Aggregations