use of WayofTime.bloodmagic.api.BloodMagicPlugin in project BloodMagic by WayofTime.
the class PluginUtil method gatherPlugins.
@SuppressWarnings("unchecked")
@Nonnull
public static List<Pair<IBloodMagicPlugin, BloodMagicPlugin>> gatherPlugins(ASMDataTable dataTable) {
Stopwatch stopwatch = Stopwatch.createStarted();
List<Pair<IBloodMagicPlugin, BloodMagicPlugin>> discoveredAnnotations = Lists.newArrayList();
Set<ASMDataTable.ASMData> discoveredPlugins = dataTable.getAll(BloodMagicPlugin.class.getName());
for (ASMDataTable.ASMData data : discoveredPlugins) {
try {
Class<?> asmClass = Class.forName(data.getClassName());
Class<? extends IBloodMagicPlugin> pluginClass = asmClass.asSubclass(IBloodMagicPlugin.class);
IBloodMagicPlugin instance = pluginClass.newInstance();
BMLog.API.info("Discovered plugin at {}", data.getClassName());
discoveredAnnotations.add(Pair.of(instance, pluginClass.getAnnotation(BloodMagicPlugin.class)));
} catch (Exception e) {
e.printStackTrace();
}
}
// Bring core plugin up to top
discoveredAnnotations.sort((o1, o2) -> {
if (o1.getLeft().getClass() == BloodMagicCorePlugin.class)
return -1;
return o1.getClass().getCanonicalName().compareToIgnoreCase(o2.getClass().getCanonicalName());
});
BMLog.API.info("Discovered {} potential plugin(s) in {}", discoveredAnnotations.size(), stopwatch.stop());
return discoveredAnnotations;
}
use of WayofTime.bloodmagic.api.BloodMagicPlugin in project BloodMagic by WayofTime.
the class PluginUtil method handlePluginStep.
public static void handlePluginStep(RegistrationStep step) {
Stopwatch total = Stopwatch.createStarted();
int errors = 0;
for (Pair<IBloodMagicPlugin, BloodMagicPlugin> plugin : BloodMagic.PLUGINS) {
Stopwatch per = Stopwatch.createStarted();
try {
step.getConsumer().accept(plugin);
} catch (Exception e) {
errors++;
BMLog.DEFAULT.error("Error handling plugin step {} at {}: {}: {}", step, plugin.getLeft().getClass(), e.getClass().getSimpleName(), e.getMessage());
}
BMLog.API.info("Handled plugin step {} at {} in {}", step, plugin.getLeft().getClass(), per.stop());
}
BMLog.API.info("Handled {} plugin(s) at step {} with {} errors in {}", BloodMagic.PLUGINS.size() - errors, step, errors, total.stop());
}
Aggregations