Search in sources :

Example 21 with Nation

use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.

the class NationCommand method listNations.

/**
	 * Send a list of all nations in the universe to player Command: /nation
	 * list
	 * 
	 * @param player
	 */
public void listNations(Player player) {
    player.sendMessage(ChatTools.formatTitle(TownySettings.getLangString("nation_plu")));
    ArrayList<String> formatedList = new ArrayList<String>();
    for (Nation nation : TownyUniverse.getDataSource().getNations()) formatedList.add(Colors.LightBlue + nation.getName() + Colors.Blue + " [" + nation.getNumTowns() + "]" + Colors.White);
    for (String line : ChatTools.list(formatedList)) player.sendMessage(line);
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) ArrayList(java.util.ArrayList)

Example 22 with Nation

use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.

the class NationCommand method nationKick.

public void nationKick(Player player, String[] names) {
    if (names.length < 1) {
        TownyMessaging.sendErrorMsg(player, "Eg: /nation kick [names]");
        return;
    }
    Resident resident;
    Nation nation;
    try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
        nation = resident.getTown().getNation();
    } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
    }
    nationKick(player, resident, nation, TownyUniverse.getDataSource().getTowns(names));
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 23 with Nation

use of com.palmergames.bukkit.towny.object.Nation 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 24 with Nation

use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.

the class NationCommand method nationLeave.

public void nationLeave(Player player) {
    Town town = null;
    Nation nation = null;
    try {
        Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
        town = resident.getTown();
        nation = town.getNation();
        nation.removeTown(town);
        /*
			 * Remove all resident titles before saving the town itself.
			 */
        List<Resident> titleRemove = new ArrayList<Resident>(town.getResidents());
        for (Resident res : titleRemove) {
            if (res.hasTitle() || res.hasSurname()) {
                res.setTitle("");
                res.setSurname("");
                TownyUniverse.getDataSource().saveResident(res);
            }
        }
        TownyUniverse.getDataSource().saveNation(nation);
        TownyUniverse.getDataSource().saveNationList();
        TownyMessaging.sendNationMessage(nation, ChatTools.color(String.format(TownySettings.getLangString("msg_nation_town_left"), town.getName())));
        TownyMessaging.sendTownMessage(town, ChatTools.color(String.format(TownySettings.getLangString("msg_town_left_nation"), nation.getName())));
    } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
    } catch (EmptyNationException en) {
        TownyUniverse.getDataSource().removeNation(en.getNation());
        TownyUniverse.getDataSource().saveNationList();
        TownyMessaging.sendGlobalMessage(ChatTools.color(String.format(TownySettings.getLangString("msg_del_nation"), en.getNation().getName())));
    } finally {
        TownyUniverse.getDataSource().saveTown(town);
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) EmptyNationException(com.palmergames.bukkit.towny.exceptions.EmptyNationException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 25 with Nation

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

Nation (com.palmergames.bukkit.towny.object.Nation)30 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)17 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)16 Resident (com.palmergames.bukkit.towny.object.Resident)16 Town (com.palmergames.bukkit.towny.object.Town)10 ArrayList (java.util.ArrayList)10 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)9 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)8 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)3 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)3 IOException (java.io.IOException)3 InvalidNameException (javax.naming.InvalidNameException)3 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)2 KeyValueFile (com.palmergames.util.KeyValueFile)2 File (java.io.File)2 Player (org.bukkit.entity.Player)2 Teleport (com.earth2me.essentials.Teleport)1 User (com.earth2me.essentials.User)1 Coord (com.palmergames.bukkit.towny.object.Coord)1 TownSpawnLevel (com.palmergames.bukkit.towny.object.TownSpawnLevel)1