Search in sources :

Example 1 with CatalogMappingDataHolder

use of org.lanternpowered.server.game.registry.CatalogMappingDataHolder in project LanternServer by LanternPowered.

the class LanternGameRegistry method getCatalogMappingData.

@SuppressWarnings("unchecked")
private List<CatalogMappingData> getCatalogMappingData(RegistryModule module) {
    Map<String, ?> mappings = null;
    if (module instanceof AlternateCatalogRegistryModule) {
        mappings = checkNotNull(((AlternateCatalogRegistryModule) module).provideCatalogMap());
    }
    final List<CatalogMappingData> data = new ArrayList<>();
    for (Field field : module.getClass().getDeclaredFields()) {
        RegisterCatalog annotation = field.getAnnotation(RegisterCatalog.class);
        if (annotation != null) {
            if (mappings == null) {
                try {
                    field.setAccessible(true);
                    mappings = (Map<String, ?>) field.get(module);
                    checkState(!mappings.isEmpty(), "The registered module: " + module.getClass().getSimpleName() + " cannot have an empty mapping during registration!");
                } catch (Exception e) {
                    this.game.getLogger().error("Failed to retrieve a registry field from module: " + module.getClass().getCanonicalName(), e);
                }
            }
            data.add(new CatalogMappingData(annotation, mappings));
        }
    }
    if (module instanceof CatalogMappingDataHolder) {
        data.addAll(((CatalogMappingDataHolder) module).getCatalogMappings());
    }
    return data;
}
Also used : Field(java.lang.reflect.Field) AlternateCatalogRegistryModule(org.spongepowered.api.registry.AlternateCatalogRegistryModule) ArrayList(java.util.ArrayList) RegisterCatalog(org.spongepowered.api.registry.util.RegisterCatalog) CatalogMappingData(org.lanternpowered.server.game.registry.CatalogMappingData) CyclicGraphException(org.lanternpowered.server.util.graph.CyclicGraphException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CatalogMappingDataHolder(org.lanternpowered.server.game.registry.CatalogMappingDataHolder)

Aggregations

IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 CatalogMappingData (org.lanternpowered.server.game.registry.CatalogMappingData)1 CatalogMappingDataHolder (org.lanternpowered.server.game.registry.CatalogMappingDataHolder)1 CyclicGraphException (org.lanternpowered.server.util.graph.CyclicGraphException)1 AlternateCatalogRegistryModule (org.spongepowered.api.registry.AlternateCatalogRegistryModule)1 RegisterCatalog (org.spongepowered.api.registry.util.RegisterCatalog)1