Search in sources :

Example 16 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, String[] split) {
    Resident resident;
    Nation nation;
    if (split.length < 2) {
        TownyMessaging.sendErrorMsg(player, "Eg: /nation enemy [add/remove] [name]");
        return;
    }
    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 enemy;
    // 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 {
                enemy = TownyUniverse.getDataSource().getNation(name);
                if (nation.equals(enemy))
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_own_nation_disallow"));
                else
                    list.add(enemy);
            } catch (NotRegisteredException e) {
            // Do nothing here as the name doesn't match a Nation
            }
        }
        if (!list.isEmpty())
            nationEnemy(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 17 with Nation

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

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

the class TownyCommand method getTownyPrices.

/**
	 * Send the list of costs for Economy to player Command: /towny prices
	 * 
	 * @param town
	 */
/*
	 * [New] Town: 100 | Nation: 500 [Upkeep] Town: 10 | Nation: 100 Town
	 * [Elden]: [Price] Plot: 100 | Outpost: 250 [Upkeep] Resident: 20 | Plot:
	 * 50 Nation [Albion]: [Upkeep] Town: 100 | Neutrality: 100
	 */
// TODO: Proceduralize and make parse function for /towny prices [town]
public List<String> getTownyPrices(Town town) {
    List<String> output = new ArrayList<String>();
    Nation nation = null;
    if (town != null)
        if (town.hasNation())
            try {
                nation = town.getNation();
            } catch (NotRegisteredException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    output.add(ChatTools.formatTitle("Prices"));
    output.add(Colors.Yellow + "[New] " + Colors.Green + "Town: " + Colors.LightGreen + TownyEconomyHandler.getFormattedBalance(TownySettings.getNewTownPrice()) + Colors.Gray + " | " + Colors.Green + "Nation: " + Colors.LightGreen + TownyEconomyHandler.getFormattedBalance(TownySettings.getNewNationPrice()));
    output.add(Colors.Yellow + "[Upkeep] " + Colors.Green + "Town: " + Colors.LightGreen + TownyEconomyHandler.getFormattedBalance(TownySettings.getTownUpkeepCost(town)) + Colors.Gray + " | " + Colors.Green + "Nation: " + Colors.LightGreen + TownyEconomyHandler.getFormattedBalance(TownySettings.getNationUpkeepCost(nation)));
    output.add(Colors.Gray + "Town upkeep is based on " + Colors.LightGreen + " the " + (TownySettings.isUpkeepByPlot() ? " number of plots" : " town level (num residents)."));
    if (town != null) {
        output.add(Colors.Yellow + "Town [" + TownyFormatter.getFormattedName(town) + "]");
        output.add(Colors.Rose + "    [Price] " + Colors.Green + "Plot: " + Colors.LightGreen + Double.toString(town.getPlotPrice()) + Colors.Gray + " | " + Colors.Green + "Outpost: " + Colors.LightGreen + TownyEconomyHandler.getFormattedBalance(TownySettings.getOutpostCost()));
        output.add(Colors.Rose + "            " + Colors.Green + "Shop: " + Colors.LightGreen + Double.toString(town.getCommercialPlotPrice()) + Colors.Gray + " | " + Colors.Green + "Embassy: " + Colors.LightGreen + Double.toString(town.getEmbassyPlotPrice()));
        output.add(Colors.Rose + "    [Taxes] " + Colors.Green + "Resident: " + Colors.LightGreen + Double.toString(town.getTaxes()) + (town.isTaxPercentage() ? "%" : "") + Colors.Gray + " | " + Colors.Green + "Plot: " + Colors.LightGreen + Double.toString(town.getPlotTax()));
        output.add(Colors.Rose + "            " + Colors.Green + "Shop: " + Colors.LightGreen + Double.toString(town.getCommercialPlotTax()) + Colors.Gray + " | " + Colors.Green + "Embassy: " + Colors.LightGreen + Double.toString(town.getEmbassyPlotTax()));
        if (nation != null) {
            output.add(Colors.Yellow + "Nation [" + TownyFormatter.getFormattedName(nation) + "]");
            output.add(Colors.Rose + "    [Taxes] " + Colors.Green + "Town: " + Colors.LightGreen + Double.toString(nation.getTaxes()) + Colors.Gray + " | " + Colors.Green + "Neutrality: " + Colors.LightGreen + TownyEconomyHandler.getFormattedBalance(TownySettings.getNationNeutralityCost()));
        }
    }
    return output;
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) ArrayList(java.util.ArrayList)

Example 19 with Nation

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

the class NationCommand method nationSet.

public void nationSet(Player player, String[] split) throws TownyException, InvalidNameException {
    if (split.length == 0) {
        player.sendMessage(ChatTools.formatTitle("/nation set"));
        player.sendMessage(ChatTools.formatCommand("", "/nation set", "king " + TownySettings.getLangString("res_2"), ""));
        player.sendMessage(ChatTools.formatCommand("", "/nation set", "capital [town]", ""));
        player.sendMessage(ChatTools.formatCommand("", "/nation set", "taxes [$]", ""));
        player.sendMessage(ChatTools.formatCommand("", "/nation set", "name [name]", ""));
        player.sendMessage(ChatTools.formatCommand("", "/nation set", "title/surname [resident] [text]", ""));
        player.sendMessage(ChatTools.formatCommand("", "/nation set", "tag [upto 4 letters] or clear", ""));
    } 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;
        }
        // TODO: Let admin's call a subfunction of this.
        if (split[0].equalsIgnoreCase("king")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_KING.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            if (split.length < 2)
                TownyMessaging.sendErrorMsg(player, "Eg: /nation set king Dumbo");
            else
                try {
                    Resident newKing = TownyUniverse.getDataSource().getResident(split[1]);
                    String oldKingsName = nation.getCapital().getMayor().getName();
                    nation.setKing(newKing);
                    plugin.deleteCache(oldKingsName);
                    plugin.deleteCache(newKing.getName());
                    TownyMessaging.sendNationMessage(nation, TownySettings.getNewKingMsg(newKing.getName(), nation.getName()));
                } catch (TownyException e) {
                    TownyMessaging.sendErrorMsg(player, e.getMessage());
                }
        } else if (split[0].equalsIgnoreCase("capital")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_CAPITOL.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            if (split.length < 2)
                TownyMessaging.sendErrorMsg(player, "Eg: /nation set capital {town name}");
            else
                try {
                    Town newCapital = TownyUniverse.getDataSource().getTown(split[1]);
                    nation.setCapital(newCapital);
                    plugin.resetCache();
                    TownyMessaging.sendNationMessage(nation, TownySettings.getNewKingMsg(newCapital.getMayor().getName(), nation.getName()));
                } catch (TownyException e) {
                    TownyMessaging.sendErrorMsg(player, e.getMessage());
                }
        } else if (split[0].equalsIgnoreCase("taxes")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_TAXES.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            if (split.length < 2)
                TownyMessaging.sendErrorMsg(player, "Eg: /nation set taxes 70");
            else {
                Integer amount = Integer.parseInt(split[1].trim());
                if (amount < 0) {
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
                    return;
                }
                try {
                    nation.setTaxes(amount);
                    TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_town_set_nation_tax"), player.getName(), split[1]));
                } catch (NumberFormatException e) {
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
                }
            }
        } else if (split[0].equalsIgnoreCase("name")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_NAME.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            if (split.length < 2)
                TownyMessaging.sendErrorMsg(player, "Eg: /nation set name Plutoria");
            else {
                if (!NameValidation.isBlacklistName(split[1]))
                    nationRename(player, nation, split[1]);
                else
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
            }
        } else if (split[0].equalsIgnoreCase("tag")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_TAG.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            if (split.length < 2)
                TownyMessaging.sendErrorMsg(player, "Eg: /nation set tag PLT");
            else if (split[1].equalsIgnoreCase("clear")) {
                try {
                    nation.setTag(" ");
                    TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_reset_nation_tag"), player.getName()));
                } catch (TownyException e) {
                    TownyMessaging.sendErrorMsg(player, e.getMessage());
                }
            } else
                nation.setTag(NameValidation.checkAndFilterName(split[1]));
            TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_set_nation_tag"), player.getName(), nation.getTag()));
        } else if (split[0].equalsIgnoreCase("title")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_TITLE.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            // Give the resident a title
            if (split.length < 2)
                TownyMessaging.sendErrorMsg(player, "Eg: /nation set title bilbo Jester ");
            else
                resident = TownyUniverse.getDataSource().getResident(split[1]);
            if (resident.hasNation()) {
                if (resident.getTown().getNation() != TownyUniverse.getDataSource().getResident(player.getName()).getTown().getNation()) {
                    TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
                    return;
                }
            } else {
                TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
                return;
            }
            split = StringMgmt.remArgs(split, 2);
            if (StringMgmt.join(split).length() > TownySettings.getMaxTitleLength()) {
                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_input_too_long"));
                return;
            }
            String title = StringMgmt.join(NameValidation.checkAndFilterArray(split));
            resident.setTitle(title + " ");
            TownyUniverse.getDataSource().saveResident(resident);
            if (resident.hasTitle())
                TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_set_title"), resident.getName(), resident.getTitle()));
            else
                TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_clear_title_surname"), "Title", resident.getName()));
        } else if (split[0].equalsIgnoreCase("surname")) {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_NATION_SET_SURNAME.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
            // Give the resident a title
            if (split.length < 2)
                TownyMessaging.sendErrorMsg(player, "Eg: /nation set surname bilbo the dwarf ");
            else
                resident = TownyUniverse.getDataSource().getResident(split[1]);
            if (resident.hasNation()) {
                if (resident.getTown().getNation() != TownyUniverse.getDataSource().getResident(player.getName()).getTown().getNation()) {
                    TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
                    return;
                }
            } else {
                TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_same_nation"), resident.getName()));
                return;
            }
            split = StringMgmt.remArgs(split, 2);
            if (StringMgmt.join(split).length() > TownySettings.getMaxTitleLength()) {
                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_input_too_long"));
                return;
            }
            String surname = StringMgmt.join(NameValidation.checkAndFilterArray(split));
            resident.setSurname(" " + surname);
            TownyUniverse.getDataSource().saveResident(resident);
            if (resident.hasSurname())
                TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_set_surname"), resident.getName(), resident.getSurname()));
            else
                TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_clear_title_surname"), "Surname", resident.getName()));
        } else {
            TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), split[0]));
            return;
        }
        TownyUniverse.getDataSource().saveNation(nation);
        TownyUniverse.getDataSource().saveNationList();
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 20 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, Nation nation, List<Nation> allies, boolean add) {
    ArrayList<Nation> remove = new ArrayList<Nation>();
    for (Nation targetNation : allies) try {
        if (add && !nation.getAllies().contains(targetNation)) {
            if (!targetNation.hasEnemy(nation)) {
                // We are not set as an enemy so we can set as ally.
                nation.addAlly(targetNation);
                TownyMessaging.sendNationMessage(targetNation, String.format(TownySettings.getLangString("msg_added_ally"), nation.getName()));
            } else {
                // We are set as an enemy so can't ally.
                remove.add(targetNation);
                TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_unable_ally_enemy"), targetNation.getName()));
            }
        } else if (nation.getAllies().contains(targetNation)) {
            nation.removeAlly(targetNation);
            TownyMessaging.sendNationMessage(targetNation, String.format(TownySettings.getLangString("msg_removed_ally"), nation.getName()));
            // Remove any mirrored ally settings from the target nation
            if (targetNation.hasAlly(nation))
                nationAlly(player, targetNation, Arrays.asList(nation), false);
        }
    } catch (AlreadyRegisteredException e) {
        remove.add(targetNation);
    } catch (NotRegisteredException e) {
        remove.add(targetNation);
    }
    for (Nation newAlly : remove) allies.remove(newAlly);
    if (allies.size() > 0) {
        String msg = "";
        for (Nation newAlly : allies) msg += newAlly.getName() + ", ";
        msg = msg.substring(0, msg.length() - 2);
        if (add)
            msg = String.format(TownySettings.getLangString("msg_allied_nations"), player.getName(), msg);
        else
            msg = String.format(TownySettings.getLangString("msg_broke_alliance"), 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