Search in sources :

Example 1 with TownyUniverse

use of com.palmergames.bukkit.towny.object.TownyUniverse 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)

Aggregations

EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)1 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)1 Town (com.palmergames.bukkit.towny.object.Town)1 TownyUniverse (com.palmergames.bukkit.towny.object.TownyUniverse)1 InvalidNameException (javax.naming.InvalidNameException)1