Search in sources :

Example 1 with LoadedMetadataEvent

use of com.palmergames.bukkit.towny.event.LoadedMetadataEvent 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

LoadedMetadataEvent (com.palmergames.bukkit.towny.event.LoadedMetadataEvent)1 TownyObject (com.palmergames.bukkit.towny.object.TownyObject)1 ArrayList (java.util.ArrayList)1