private CrateLoader(Settings settings) {
ServiceLoader<CrateComponent> crateComponents = ServiceLoader.load(CrateComponent.class);
plugins = new ArrayList<>();
MapBuilder<Plugin, List<OnModuleReference>> onModuleReferences = MapBuilder.newMapBuilder();
for (CrateComponent crateComponent : crateComponents) {
Plugin plugin = crateComponent.createPlugin(settings);
plugins.add(plugin);
List<OnModuleReference> list = Lists.newArrayList();
for (Method method : plugin.getClass().getDeclaredMethods()) {
if (!method.getName().equals("onModule")) {
continue;
}
if (method.getParameterTypes().length == 0 || method.getParameterTypes().length > 1) {
logger.warn("Plugin: {} implementing onModule with no parameters or more than one parameter", plugin.name());
continue;
}
Class moduleClass = method.getParameterTypes()[0];
if (!Module.class.isAssignableFrom(moduleClass)) {
logger.warn("Plugin: {} implementing onModule by the type is not of Module type {}", plugin.name(), moduleClass);
continue;
}
method.setAccessible(true);
//noinspection unchecked
list.add(new OnModuleReference(moduleClass, method));