Search in sources :

Example 11 with Nation

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

the class NationCommand method nationAlly.

public void nationAlly(Player player, String[] split) {
    if (split.length < 2) {
        TownyMessaging.sendErrorMsg(player, "Eg: /nation ally [add/remove] [name]");
        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;
    }
    ArrayList<Nation> list = new ArrayList<Nation>();
    Nation ally;
    // test add or remove
    String test = split[0];
    String[] newSplit = StringMgmt.remFirstArg(split);
    if ((test.equalsIgnoreCase("remove") || test.equalsIgnoreCase("add")) && newSplit.length > 0) {
        for (String name : newSplit) {
            try {
                ally = TownyUniverse.getDataSource().getNation(name);
                if (nation.equals(ally))
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_own_nation_disallow"));
                else
                    list.add(ally);
            } catch (NotRegisteredException e) {
            // Do nothing here as the name doesn't match a Nation
            }
        }
        if (!list.isEmpty())
            nationAlly(player, nation, list, test.equalsIgnoreCase("add"));
    } else {
        TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), "[add/remove]"));
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 12 with Nation

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

the class NationCommand method nationWithdraw.

private void nationWithdraw(Player player, int amount) {
    Resident resident;
    Nation nation;
    try {
        if (!TownySettings.geNationBankAllowWithdrawls())
            throw new TownyException(TownySettings.getLangString("msg_err_withdraw_disabled"));
        if (amount < 0)
            // TODO
            throw new TownyException(TownySettings.getLangString("msg_err_negative_money"));
        resident = TownyUniverse.getDataSource().getResident(player.getName());
        nation = resident.getTown().getNation();
        nation.withdrawFromBank(resident, amount);
        TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_xx_withdrew_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 13 with Nation

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

the class BaseCommand method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
    LinkedList<String> output = new LinkedList<String>();
    String lastArg = "";
    // Get the last argument
    if (args.length > 0) {
        lastArg = args[args.length - 1].toLowerCase();
    }
    if (!lastArg.equalsIgnoreCase("")) {
        // Match nations
        for (Nation nation : TownyUniverse.getDataSource().getNations()) {
            if (nation.getName().toLowerCase().startsWith(lastArg)) {
                output.add(nation.getName());
            }
        }
        // Match towns
        for (Town town : TownyUniverse.getDataSource().getTowns()) {
            if (town.getName().toLowerCase().startsWith(lastArg)) {
                output.add(town.getName());
            }
        }
        // Match residents
        for (Resident resident : TownyUniverse.getDataSource().getResidents()) {
            if (resident.getName().toLowerCase().startsWith(lastArg)) {
                output.add(resident.getName());
            }
        }
    }
    return output;
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) LinkedList(java.util.LinkedList)

Example 14 with Nation

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

the class NationCommand method parseNationCommand.

public void parseNationCommand(Player player, String[] split) {
    String nationCom = "/nation";
    try {
        if (split.length == 0)
            try {
                Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                Town town = resident.getTown();
                Nation nation = town.getNation();
                TownyMessaging.sendMessage(player, TownyFormatter.getStatus(nation));
            } catch (NotRegisteredException x) {
                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_nation"));
            }
        else if (split[0].equalsIgnoreCase("?"))
            for (String line : nation_help) player.sendMessage(line);
        else if (split[0].equalsIgnoreCase("list")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_LIST.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            listNations(player);
        } else if (split[0].equalsIgnoreCase("new")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_NEW.getNode()))
                throw new TownyException(TownySettings.getNotPermToNewNationLine());
            // newNation(Player,String,Town)
            if (split.length == 1)
                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_specify_nation_name"));
            else if (split.length == 2) {
                Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                if (!resident.isMayor() && !resident.getTown().hasAssistant(resident))
                    throw new TownyException(TownySettings.getLangString("msg_peasant_right"));
                newNation(player, split[1], resident.getTown().getName());
            } else {
                // TODO: Check if player is an admin
                newNation(player, split[1], split[2]);
            }
        } else if (split[0].equalsIgnoreCase("leave")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_LEAVE.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            nationLeave(player);
        } else if (split[0].equalsIgnoreCase("withdraw")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_WITHDRAW.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            if (split.length == 2)
                try {
                    nationWithdraw(player, Integer.parseInt(split[1].trim()));
                } catch (NumberFormatException e) {
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
                }
            else
                TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_must_specify_amnt"), nationCom));
        } else if (split[0].equalsIgnoreCase("deposit")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_DEPOSIT.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            if (split.length == 2)
                try {
                    nationDeposit(player, Integer.parseInt(split[1].trim()));
                } catch (NumberFormatException e) {
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
                }
            else
                TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_must_specify_amnt"), nationCom + " deposit"));
        } else {
            String[] newSplit = StringMgmt.remFirstArg(split);
            if (split[0].equalsIgnoreCase("rank")) {
                /*
					 * Rank perm tests are performed in the nationrank method.
					 */
                nationRank(player, newSplit);
            } else if (split[0].equalsIgnoreCase("king")) {
                if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_KING.getNode()))
                    throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
                nationKing(player, newSplit);
            } else if (split[0].equalsIgnoreCase("add")) {
                if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_ADD.getNode()))
                    throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
                nationAdd(player, newSplit);
            } else if (split[0].equalsIgnoreCase("kick")) {
                if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_KICK.getNode()))
                    throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
                nationKick(player, newSplit);
            } else if (split[0].equalsIgnoreCase("set")) {
                /*
					 * perm test performed in method.
					 */
                nationSet(player, newSplit);
            } else if (split[0].equalsIgnoreCase("toggle")) {
                /*
					 * perm test performed in method.
					 */
                nationToggle(player, newSplit);
            } else if (split[0].equalsIgnoreCase("ally")) {
                if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_ALLY.getNode()))
                    throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
                nationAlly(player, newSplit);
            } else if (split[0].equalsIgnoreCase("enemy")) {
                if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_ENEMY.getNode()))
                    throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
                nationEnemy(player, newSplit);
            } else if (split[0].equalsIgnoreCase("delete")) {
                if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_DELETE.getNode()))
                    throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
                nationDelete(player, newSplit);
            } else if (split[0].equalsIgnoreCase("online")) {
                if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_ONLINE.getNode()))
                    throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
                try {
                    Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                    Town town = resident.getTown();
                    Nation nation = town.getNation();
                    TownyMessaging.sendMessage(player, TownyFormatter.getFormattedOnlineResidents(TownySettings.getLangString("msg_nation_online"), nation, player));
                } catch (NotRegisteredException x) {
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_nation"));
                }
            } else
                try {
                    Nation nation = TownyUniverse.getDataSource().getNation(split[0]);
                    TownyMessaging.sendMessage(player, TownyFormatter.getStatus(nation));
                } catch (NotRegisteredException x) {
                    TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_registered_1"), split[0]));
                }
        }
    } catch (Exception x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) 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 15 with Nation

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

the class NationCommand method nationEnemy.

public void nationEnemy(Player player, Nation nation, List<Nation> enemies, boolean add) {
    ArrayList<Nation> remove = new ArrayList<Nation>();
    for (Nation targetNation : enemies) try {
        if (add && !nation.getEnemies().contains(targetNation)) {
            nation.addEnemy(targetNation);
            TownyMessaging.sendNationMessage(targetNation, String.format(TownySettings.getLangString("msg_added_enemy"), nation.getName()));
            // Remove any ally settings from the target nation
            if (targetNation.hasAlly(nation))
                nationAlly(player, targetNation, Arrays.asList(nation), false);
        } else if (nation.getEnemies().contains(targetNation)) {
            nation.removeEnemy(targetNation);
            TownyMessaging.sendNationMessage(targetNation, String.format(TownySettings.getLangString("msg_removed_enemy"), nation.getName()));
        }
    } catch (AlreadyRegisteredException e) {
        remove.add(targetNation);
    } catch (NotRegisteredException e) {
        remove.add(targetNation);
    }
    for (Nation newEnemy : remove) enemies.remove(newEnemy);
    if (enemies.size() > 0) {
        String msg = "";
        for (Nation newEnemy : enemies) msg += newEnemy.getName() + ", ";
        msg = msg.substring(0, msg.length() - 2);
        if (add)
            msg = String.format(TownySettings.getLangString("msg_enemy_nations"), player.getName(), msg);
        else
            msg = String.format(TownySettings.getLangString("msg_enemy_to_neutral"), player.getName(), msg);
        TownyMessaging.sendNationMessage(nation, ChatTools.color(msg));
        TownyUniverse.getDataSource().saveNations();
        plugin.resetCache();
    } else
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) ArrayList(java.util.ArrayList)

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