use of org.spongepowered.api.registry.AlternateCatalogRegistryModule 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;
}
use of org.spongepowered.api.registry.AlternateCatalogRegistryModule in project SpongeCommon by SpongePowered.
the class RegistryModuleLoader method getCatalogMap.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Map<String, ?> getCatalogMap(RegistryModule module) {
if (module instanceof AlternateCatalogRegistryModule) {
return checkNotNull(((AlternateCatalogRegistryModule) module).provideCatalogMap());
}
for (Field field : module.getClass().getDeclaredFields()) {
RegisterCatalog annotation = field.getAnnotation(RegisterCatalog.class);
if (annotation != null) {
try {
field.setAccessible(true);
Map<String, ?> map = (Map<String, ?>) field.get(module);
checkState(!map.isEmpty(), "The registered module: " + module.getClass().getSimpleName() + " cannot have an empty mapping during registration!");
return checkNotNull(map);
} catch (Exception e) {
SpongeImpl.getLogger().error("Failed to retrieve a registry field from module: " + module.getClass().getCanonicalName());
}
}
}
throw new IllegalStateException("Registry module does not have a catalog map! Registry: " + module.getClass().getCanonicalName());
}
Aggregations