use of com.palmergames.bukkit.towny.exceptions.EconomyException in project Towny by ElgarL.
the class NationCommand method nationDeposit.
private void nationDeposit(Player player, int amount) {
Resident resident;
Nation nation;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
nation = resident.getTown().getNation();
double bankcap = TownySettings.getNationBankCap();
if (bankcap > 0) {
if (amount + nation.getHoldingBalance() > bankcap)
throw new TownyException(String.format(TownySettings.getLangString("msg_err_deposit_capped"), bankcap));
}
if (amount < 0)
throw new TownyException(TownySettings.getLangString("msg_err_negative_money"));
if (!resident.payTo(amount, nation, "Nation Deposit"))
throw new TownyException(TownySettings.getLangString("msg_insuf_funds"));
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_xx_deposited_xx"), resident.getName(), amount, "nation"));
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
} catch (EconomyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
use of com.palmergames.bukkit.towny.exceptions.EconomyException in project Towny by ElgarL.
the class NationCommand method newNation.
/**
* Create a new nation. Command: /nation new [nation] *[capital]
*
* @param player
*/
public void newNation(Player player, String name, String capitalName) {
TownyUniverse universe = plugin.getTownyUniverse();
try {
Town town = TownyUniverse.getDataSource().getTown(capitalName);
if (town.hasNation())
throw new TownyException(TownySettings.getLangString("msg_err_already_nation"));
// Check the name is valid and doesn't already exist.
String filteredName;
try {
filteredName = NameValidation.checkAndFilterName(name);
} catch (InvalidNameException e) {
filteredName = null;
}
if ((filteredName == null) || TownyUniverse.getDataSource().hasNation(filteredName))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_name"), name));
if (TownySettings.isUsingEconomy() && !town.pay(TownySettings.getNewNationPrice(), "New Nation Cost"))
throw new TownyException(TownySettings.getLangString("msg_no_funds_new_nation"));
newNation(universe, name, town);
/*
* universe.newNation(name); Nation nation =
* universe.getNation(name); nation.addTown(town);
* nation.setCapital(town);
*
* universe.getDataSource().saveTown(town);
* universe.getDataSource().saveNation(nation);
* universe.getDataSource().saveNationList();
*/
TownyMessaging.sendGlobalMessage(TownySettings.getNewNationMsg(player.getName(), name));
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
// TODO: delete town data that might have been done
} catch (EconomyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
use of com.palmergames.bukkit.towny.exceptions.EconomyException in project Towny by ElgarL.
the class TownyFormatter method getTaxStatus.
/**
* Returns the tax info this resident will have to pay at the next new day.
*
* @param resident
* @return tax status message
*/
public static List<String> getTaxStatus(Resident resident) {
List<String> out = new ArrayList<String>();
Town town = null;
double plotTax = 0.0;
out.add(ChatTools.formatTitle(getFormattedName(resident) + ((BukkitTools.isOnline(resident.getName())) ? Colors.LightGreen + " (Online)" : "")));
if (resident.hasTown()) {
try {
town = resident.getTown();
out.add(Colors.Green + "Owner of: " + Colors.LightGreen + resident.getTownBlocks().size() + " plots");
if (TownyPerms.getResidentPerms(resident).containsKey("towny.tax_exempt")) {
out.add(Colors.Green + "Staff are exempt from paying town taxes.");
} else {
if (town.isTaxPercentage()) {
out.add(Colors.Green + "Town Tax: " + Colors.LightGreen + (resident.getHoldingBalance() * town.getTaxes() / 100));
} else {
out.add(Colors.Green + "Town Tax: " + Colors.LightGreen + town.getTaxes());
if ((resident.getTownBlocks().size() > 0)) {
for (TownBlock townBlock : new ArrayList<TownBlock>(resident.getTownBlocks())) {
plotTax += townBlock.getType().getTax(townBlock.getTown());
}
out.add(Colors.Green + "Total Plot Taxes: " + Colors.LightGreen + plotTax);
}
out.add(Colors.Green + "Total Tax to pay: " + Colors.LightGreen + (town.getTaxes() + plotTax));
}
}
} catch (NotRegisteredException e) {
// Failed to fetch town
} catch (EconomyException e) {
// Economy failed
}
}
return out;
}
use of com.palmergames.bukkit.towny.exceptions.EconomyException in project Towny by ElgarL.
the class NationCommand method nationToggle.
public void nationToggle(Player player, String[] split) throws TownyException {
if (split.length == 0) {
player.sendMessage(ChatTools.formatTitle("/nation toggle"));
player.sendMessage(ChatTools.formatCommand("", "/nation toggle", "neutral", ""));
} else {
Resident resident;
Nation nation;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
nation = resident.getTown().getNation();
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
if (split[0].equalsIgnoreCase("neutral")) {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_TOGGLE_NEUTRAL.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
try {
if (!TownySettings.isDeclaringNeutral())
throw new TownyException(TownySettings.getLangString("msg_neutral_disabled"));
boolean choice = !nation.isNeutral();
Double cost = TownySettings.getNationNeutralityCost();
if (choice && TownySettings.isUsingEconomy() && !nation.pay(cost, "Nation Neutrality Cost"))
throw new TownyException(TownySettings.getLangString("msg_nation_cant_neutral"));
nation.setNeutral(choice);
// for neutral
if (TownySettings.isUsingEconomy() && cost > 0)
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_you_paid"), TownyEconomyHandler.getFormattedBalance(cost)));
else
TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_nation_set_neutral"));
TownyMessaging.sendNationMessage(nation, TownySettings.getLangString("msg_nation_neutral") + (nation.isNeutral() ? Colors.Green : Colors.Red + " not") + " neutral.");
} catch (EconomyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
} catch (TownyException e) {
try {
nation.setNeutral(false);
} catch (TownyException e1) {
e1.printStackTrace();
}
TownyMessaging.sendErrorMsg(player, e.getMessage());
} catch (Exception e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), "nation"));
return;
}
plugin.getTownyUniverse();
TownyUniverse.getDataSource().saveNation(nation);
}
}
use of com.palmergames.bukkit.towny.exceptions.EconomyException in project Towny by ElgarL.
the class NationCommand method newNation.
public Nation newNation(TownyUniverse universe, String name, Town town) throws AlreadyRegisteredException, NotRegisteredException {
TownyUniverse.getDataSource().newNation(name);
Nation nation = TownyUniverse.getDataSource().getNation(name);
nation.addTown(town);
nation.setCapital(town);
if (TownySettings.isUsingEconomy()) {
//TODO
try {
nation.setBalance(0, "Deleting Nation");
} catch (EconomyException e) {
e.printStackTrace();
}
}
TownyUniverse.getDataSource().saveTown(town);
TownyUniverse.getDataSource().saveNation(nation);
TownyUniverse.getDataSource().saveNationList();
return nation;
}
Aggregations