Search in sources :

Example 1 with Government

use of com.palmergames.bukkit.towny.object.Government in project Towny by TownyAdvanced.

the class TownyCommand method getTopBankBalance.

public List<String> getTopBankBalance(final List<Government> governments) {
    final int maxListing = TownySettings.getTownyTopSize();
    final List<String> output = new ArrayList<>();
    // Sort by their bank balance first
    governments.sort(GovernmentComparators.BY_BANK_BALANCE);
    int index = 0;
    // Loop through each one (already sorted) and add to the map
    for (final Government gov : governments) {
        index++;
        if (maxListing != -1 && index > maxListing) {
            break;
        }
        output.add(String.format(Colors.LightGray + "%-20s " + Colors.Gold + "|" + Colors.Blue + " %s", gov.getFormattedName(), getMoney(gov.getAccount().getCachedBalance())));
    }
    return output;
}
Also used : Government(com.palmergames.bukkit.towny.object.Government) ArrayList(java.util.ArrayList)

Example 2 with Government

use of com.palmergames.bukkit.towny.object.Government in project Towny by TownyAdvanced.

the class TownyCommand method parseTopCommand.

private void parseTopCommand(CommandSender sender, String[] args) throws TownyException {
    List<String> townyTop = new ArrayList<>();
    TownyUniverse universe = TownyUniverse.getInstance();
    if (args.length == 0 || args[0].equalsIgnoreCase("?")) {
        townyTop.add(ChatTools.formatTitle("/towny top"));
        townyTop.add(ChatTools.formatCommand("", "/towny top", "residents [all/town/nation]", ""));
        townyTop.add(ChatTools.formatCommand("", "/towny top", "land [all/resident/town]", ""));
        townyTop.add(ChatTools.formatCommand("", "/towny top", "balance [all/town/nation]", ""));
        for (String line : townyTop) TownyMessaging.sendMessage(sender, line);
        return;
    }
    if (!TownyUniverse.getInstance().getPermissionSource().testPermission(sender, PermissionNodes.TOWNY_COMMAND_TOWNY_TOP.getNode(args[0].toLowerCase())))
        throw new TownyException(Translatable.of("msg_err_command_disable"));
    if (args[0].equalsIgnoreCase("residents"))
        if (args.length == 1 || args[1].equalsIgnoreCase("all")) {
            List<ResidentList> list = new ArrayList<>(universe.getTowns());
            list.addAll(universe.getNations());
            townyTop.add(ChatTools.formatTitle("Most Residents"));
            townyTop.addAll(getMostResidents(list));
        } else if (args[1].equalsIgnoreCase("town")) {
            townyTop.add(ChatTools.formatTitle("Most Residents in a Town"));
            townyTop.addAll(getMostResidents(new ArrayList<>(universe.getTowns())));
        } else if (args[1].equalsIgnoreCase("nation")) {
            townyTop.add(ChatTools.formatTitle("Most Residents in a Nation"));
            townyTop.addAll(getMostResidents(new ArrayList<>(universe.getNations())));
        } else
            TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_err_invalid_sub"));
    else if (args[0].equalsIgnoreCase("land"))
        if (args.length == 1 || args[1].equalsIgnoreCase("all")) {
            List<TownBlockOwner> list = new ArrayList<>(universe.getResidents());
            list.addAll(universe.getTowns());
            townyTop.add(ChatTools.formatTitle("Most Land Owned"));
            townyTop.addAll(getMostLand(list));
        } else if (args[1].equalsIgnoreCase("resident")) {
            townyTop.add(ChatTools.formatTitle("Most Land Owned by Resident"));
            townyTop.addAll(getMostLand(new ArrayList<>(universe.getResidents())));
        } else if (args[1].equalsIgnoreCase("town")) {
            townyTop.add(ChatTools.formatTitle("Most Land Owned by Town"));
            townyTop.addAll(getMostLand(new ArrayList<>(universe.getTowns())));
        } else
            TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_err_invalid_sub"));
    else if (args[0].equalsIgnoreCase("balance")) {
        Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
            if (args.length == 1 || args[1].equalsIgnoreCase("all")) {
                List<Government> list = new ArrayList<>();
                list.addAll(universe.getTowns());
                list.addAll(universe.getNations());
                townyTop.add(ChatTools.formatTitle("Top Bank Balances"));
                townyTop.addAll(getTopBankBalance(list));
            } else if (args[1].equalsIgnoreCase("town")) {
                List<Government> list = new ArrayList<>(universe.getTowns());
                townyTop.add(ChatTools.formatTitle("Top Bank Balances by Town"));
                townyTop.addAll(getTopBankBalance(list));
            } else if (args[1].equalsIgnoreCase("nation")) {
                List<Government> list = new ArrayList<>(universe.getNations());
                townyTop.add(ChatTools.formatTitle("Top Bank Balances by Nation"));
                townyTop.addAll(getTopBankBalance(list));
            } else {
                TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_err_invalid_sub"));
            }
            for (String line : townyTop) TownyMessaging.sendMessage(sender, line);
        });
        return;
    } else
        TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_err_invalid_sub"));
    for (String line : townyTop) TownyMessaging.sendMessage(sender, line);
}
Also used : Government(com.palmergames.bukkit.towny.object.Government) TownBlockOwner(com.palmergames.bukkit.towny.object.TownBlockOwner) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ResidentList(com.palmergames.bukkit.towny.object.ResidentList) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 3 with Government

use of com.palmergames.bukkit.towny.object.Government in project SiegeWar by TownyAdvanced.

the class SiegeCampUtil method finishSiegeCamp.

/**
 * Finish a SiegeCamp and determine whether the SiegeCamp was successful.
 * Penalize failed SiegeCamps by making the attacking Town unable to begin another SiegeCamp for a time period.
 * @param camp {@link SiegeCamp} to finish.
 */
private static void finishSiegeCamp(SiegeCamp camp) {
    if (camp.getAttackerPoints() >= SiegeWarSettings.getSiegeCampPointsForSuccess()) {
        // Attackers scored enough points to start the Siege in ernest.
        camp.startSiege();
    } else {
        // Attackers were thwarted, they are penalized with a cooldown on making another SiegeCamp on this town.
        Government attacker = camp.getAttacker();
        if (attacker instanceof Town)
            TownyMessaging.sendPrefixedTownMessage((Town) attacker, Translatable.of("msg_err_your_siegecamp_failed_you_must_wait_x", TimeMgmt.formatCountdownTime(SiegeWarSettings.getFailedSiegeCampCooldown())));
        else if (attacker instanceof Nation)
            TownyMessaging.sendPrefixedNationMessage((Nation) attacker, Translatable.of("msg_err_your_siegecamp_failed_you_must_wait_x", TimeMgmt.formatCountdownTime(SiegeWarSettings.getFailedSiegeCampCooldown())));
        String failedCamps = TownMetaDataController.getFailedSiegeCampList(camp.getTargetTown());
        if (failedCamps == null) {
            // No metadata, start a new failedCamps string.
            failedCamps = camp.getTargetTown().getUUID() + ":" + System.currentTimeMillis();
        } else {
            // This target town already had at least one failed siegecamp.
            failedCamps += "," + camp.getTargetTown().getUUID() + ":" + System.currentTimeMillis() + (SiegeWarSettings.getFailedSiegeCampCooldown() * 1000);
        }
        // Set the metadata on the target town.
        TownMetaDataController.setFailedCampSiegeList(camp.getTargetTown(), failedCamps);
        // Remove the SiegeCamp.
        SiegeController.removeSiegeCamp(camp);
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Government(com.palmergames.bukkit.towny.object.Government) Town(com.palmergames.bukkit.towny.object.Town)

Example 4 with Government

use of com.palmergames.bukkit.towny.object.Government in project SiegeWar by TownyAdvanced.

the class SiegeWarAllegianceUtil method calculateCandidateSiegePlayerSide.

public static SiegeSide calculateCandidateSiegePlayerSide(Player deadPlayer, Town deadResidentTown, Siege candidateSiege) {
    // Look for defender
    Government defendingGovernment = candidateSiege.getDefender();
    switch(candidateSiege.getSiegeType()) {
        case CONQUEST:
        case SUPPRESSION:
        case LIBERATION:
            // In the above sieges, defenders can be town guards
            if (isTownGuard(deadPlayer, deadResidentTown, defendingGovernment))
                return SiegeSide.DEFENDERS;
        case REVOLT:
            // In the above sieges, defenders can be nation/allied soldiers
            if (isNationSoldierOrAlliedSoldier(deadPlayer, deadResidentTown, defendingGovernment))
                return SiegeSide.DEFENDERS;
    }
    // Look for attacker
    Government attackingGovernment = candidateSiege.getAttacker();
    switch(candidateSiege.getSiegeType()) {
        case REVOLT:
            // In the above sieges, attackers can be town guards
            if (isTownGuard(deadPlayer, deadResidentTown, attackingGovernment))
                return SiegeSide.ATTACKERS;
        case CONQUEST:
        case SUPPRESSION:
        case LIBERATION:
            // In the above sieges, attackers can be nation/allied soldiers
            if (isNationSoldierOrAlliedSoldier(deadPlayer, deadResidentTown, attackingGovernment))
                return SiegeSide.ATTACKERS;
    }
    return SiegeSide.NOBODY;
}
Also used : Government(com.palmergames.bukkit.towny.object.Government)

Aggregations

Government (com.palmergames.bukkit.towny.object.Government)4 ArrayList (java.util.ArrayList)2 TownyUniverse (com.palmergames.bukkit.towny.TownyUniverse)1 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)1 Nation (com.palmergames.bukkit.towny.object.Nation)1 ResidentList (com.palmergames.bukkit.towny.object.ResidentList)1 Town (com.palmergames.bukkit.towny.object.Town)1 TownBlockOwner (com.palmergames.bukkit.towny.object.TownBlockOwner)1 List (java.util.List)1