Search in sources :

Example 1 with TownyObject

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

the class TownyCommand method getMostResidents.

public List<String> getMostResidents(List<ResidentList> list) {
    final int maxListing = TownySettings.getTownyTopSize();
    List<String> output = new ArrayList<>();
    list.sort(Comparator.comparingInt(residentList -> residentList.getResidents().size()));
    Collections.reverse(list);
    int n = 0;
    for (ResidentList residentList : list) {
        n++;
        if (maxListing != -1 && n > maxListing)
            break;
        output.add(String.format(Colors.Blue + "%30s " + Colors.Gold + "|" + Colors.LightGray + " %10d", ((TownyObject) residentList).getFormattedName(), residentList.getResidents().size()));
    }
    return output;
}
Also used : Plugin(org.bukkit.plugin.Plugin) Translation(com.palmergames.bukkit.towny.object.Translation) Arrays(java.util.Arrays) TownBlockType(com.palmergames.bukkit.towny.object.TownBlockType) Translatable(com.palmergames.bukkit.towny.object.Translatable) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlockTypeHandler(com.palmergames.bukkit.towny.object.TownBlockTypeHandler) Player(org.bukkit.entity.Player) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse) ArrayList(java.util.ArrayList) TownBlockOwner(com.palmergames.bukkit.towny.object.TownBlockOwner) TimeMgmt(com.palmergames.util.TimeMgmt) TownyCommandAddonAPI(com.palmergames.bukkit.towny.TownyCommandAddonAPI) HUDManager(com.palmergames.bukkit.towny.huds.HUDManager) Locale(java.util.Locale) Translator(com.palmergames.bukkit.towny.object.Translator) SelectionGUI(com.palmergames.bukkit.towny.object.gui.SelectionGUI) NameUtil(com.palmergames.bukkit.towny.utils.NameUtil) GovernmentComparators(com.palmergames.bukkit.towny.object.comparators.GovernmentComparators) ChatTools(com.palmergames.bukkit.util.ChatTools) Town(com.palmergames.bukkit.towny.object.Town) Bukkit(org.bukkit.Bukkit) StringMgmt(com.palmergames.util.StringMgmt) TownyAsciiMap(com.palmergames.bukkit.towny.TownyAsciiMap) TownyUpdateChecker(com.palmergames.bukkit.towny.TownyUpdateChecker) TownyPermissionSource(com.palmergames.bukkit.towny.permissions.TownyPermissionSource) Nation(com.palmergames.bukkit.towny.object.Nation) CommandSender(org.bukkit.command.CommandSender) Colors(com.palmergames.bukkit.util.Colors) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) DecimalFormat(java.text.DecimalFormat) TownyEconomyHandler(com.palmergames.bukkit.towny.TownyEconomyHandler) TownyObject(com.palmergames.bukkit.towny.object.TownyObject) CommandExecutor(org.bukkit.command.CommandExecutor) TownyAPI(com.palmergames.bukkit.towny.TownyAPI) List(java.util.List) CommandType(com.palmergames.bukkit.towny.TownyCommandAddonAPI.CommandType) PermissionNodes(com.palmergames.bukkit.towny.permissions.PermissionNodes) Government(com.palmergames.bukkit.towny.object.Government) Command(org.bukkit.command.Command) Towny(com.palmergames.bukkit.towny.Towny) ResidentUtil(com.palmergames.bukkit.towny.utils.ResidentUtil) Comparator(java.util.Comparator) TownyMessaging(com.palmergames.bukkit.towny.TownyMessaging) TownySettings(com.palmergames.bukkit.towny.TownySettings) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) ResidentList(com.palmergames.bukkit.towny.object.ResidentList) Collections(java.util.Collections) ArrayList(java.util.ArrayList) ResidentList(com.palmergames.bukkit.towny.object.ResidentList) TownyObject(com.palmergames.bukkit.towny.object.TownyObject)

Example 2 with TownyObject

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

the class MetadataLoader method runDeserialization.

private void runDeserialization() {
    if (storedMetadata.isEmpty())
        return;
    List<CustomDataField<?>> deserializedFields = new ArrayList<>();
    for (TownyObject tObj : storedMetadata) {
        // Convert all RawDataFields to actual CustomDataField classes.
        for (CustomDataField<?> cdf : tObj.getMetadata()) {
            if (!(cdf instanceof RawDataField))
                continue;
            CustomDataField<?> convertedCDF = convertRawMetadata((RawDataField) cdf);
            if (convertedCDF == null || convertedCDF instanceof RawDataField)
                continue;
            deserializedFields.add(convertedCDF);
        }
        if (!deserializedFields.isEmpty()) {
            for (CustomDataField<?> cdf : deserializedFields) {
                // Will override the metadata
                tObj.addMetaData(cdf, false);
            }
            deserializedFields.clear();
        }
    }
    storedMetadata.clear();
    // Reduce memory alloc after load.
    storedMetadata.trimToSize();
    // Call event
    Bukkit.getPluginManager().callEvent(new LoadedMetadataEvent());
}
Also used : ArrayList(java.util.ArrayList) LoadedMetadataEvent(com.palmergames.bukkit.towny.event.LoadedMetadataEvent) TownyObject(com.palmergames.bukkit.towny.object.TownyObject)

Aggregations

TownyObject (com.palmergames.bukkit.towny.object.TownyObject)2 ArrayList (java.util.ArrayList)2 Towny (com.palmergames.bukkit.towny.Towny)1 TownyAPI (com.palmergames.bukkit.towny.TownyAPI)1 TownyAsciiMap (com.palmergames.bukkit.towny.TownyAsciiMap)1 TownyCommandAddonAPI (com.palmergames.bukkit.towny.TownyCommandAddonAPI)1 CommandType (com.palmergames.bukkit.towny.TownyCommandAddonAPI.CommandType)1 TownyEconomyHandler (com.palmergames.bukkit.towny.TownyEconomyHandler)1 TownyMessaging (com.palmergames.bukkit.towny.TownyMessaging)1 TownySettings (com.palmergames.bukkit.towny.TownySettings)1 TownyUniverse (com.palmergames.bukkit.towny.TownyUniverse)1 TownyUpdateChecker (com.palmergames.bukkit.towny.TownyUpdateChecker)1 LoadedMetadataEvent (com.palmergames.bukkit.towny.event.LoadedMetadataEvent)1 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)1 HUDManager (com.palmergames.bukkit.towny.huds.HUDManager)1 Government (com.palmergames.bukkit.towny.object.Government)1 Nation (com.palmergames.bukkit.towny.object.Nation)1 Resident (com.palmergames.bukkit.towny.object.Resident)1 ResidentList (com.palmergames.bukkit.towny.object.ResidentList)1 Town (com.palmergames.bukkit.towny.object.Town)1