use of org.lanternpowered.server.game.registry.CatalogMappingData 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.lanternpowered.server.game.registry.CatalogMappingData in project LanternServer by LanternPowered.
the class AccessoryRegistryModule method getCatalogMappings.
@Override
public List<CatalogMappingData> getCatalogMappings() {
final ImmutableList.Builder<CatalogMappingData> mappingData = ImmutableList.builder();
mappingData.addAll(super.getCatalogMappings());
final ImmutableMap.Builder<String, Accessory> topHatMappings = ImmutableMap.builder();
getAll().stream().filter(accessory -> accessory instanceof TopHat).forEach(accessory -> topHatMappings.put(accessory.getName().replace("_top_hat", ""), accessory));
mappingData.add(new CatalogMappingData(TopHats.class, topHatMappings.build()));
return mappingData.build();
}
use of org.lanternpowered.server.game.registry.CatalogMappingData in project LanternServer by LanternPowered.
the class LanternGameRegistry method tryModulePhaseRegistration.
private void tryModulePhaseRegistration(RegistryModule module) {
try {
final Set<Method> methods = getCustomRegistrations(module);
methods.stream().filter(this::isProperPhase).forEach(method -> invokeCustomRegistration(module, method));
if (isProperPhase(module)) {
module.registerDefaults();
for (CatalogMappingData data : getCatalogMappingData(module)) {
final Map<String, ?> mappings = data.getMappings();
if (mappings.isEmpty()) {
return;
}
RegistryHelper.mapFields(data.getTarget(), mappings, data.getIgnoredFields());
}
}
} catch (Exception e) {
throw new RuntimeException("Error trying to initialize module: " + module.getClass().getCanonicalName(), e);
}
}
Aggregations