Search in sources :

Example 6 with EconomyException

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());
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 7 with EconomyException

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());
    }
}
Also used : EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) InvalidNameException(javax.naming.InvalidNameException) Town(com.palmergames.bukkit.towny.object.Town) TownyUniverse(com.palmergames.bukkit.towny.object.TownyUniverse) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 8 with EconomyException

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;
}
Also used : EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 9 with EconomyException

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);
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) Resident(com.palmergames.bukkit.towny.object.Resident) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) EmptyNationException(com.palmergames.bukkit.towny.exceptions.EmptyNationException) EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) InvalidNameException(javax.naming.InvalidNameException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 10 with EconomyException

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;
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException)

Aggregations

EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)16 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)13 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)9 Nation (com.palmergames.bukkit.towny.object.Nation)8 Resident (com.palmergames.bukkit.towny.object.Resident)5 Town (com.palmergames.bukkit.towny.object.Town)5 ArrayList (java.util.ArrayList)3 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)2 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)2 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)2 CellUnderAttack (com.palmergames.bukkit.towny.war.flagwar.CellUnderAttack)2 InvalidNameException (javax.naming.InvalidNameException)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 Teleport (com.earth2me.essentials.Teleport)1 User (com.earth2me.essentials.User)1 PlotClearEvent (com.palmergames.bukkit.towny.event.PlotClearEvent)1 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)1 TownBlockOwner (com.palmergames.bukkit.towny.object.TownBlockOwner)1 TownSpawnLevel (com.palmergames.bukkit.towny.object.TownSpawnLevel)1