Search in sources :

Example 1 with BloodMagicPlugin

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;
}
Also used : ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) IBloodMagicPlugin(WayofTime.bloodmagic.api.IBloodMagicPlugin) BloodMagicPlugin(WayofTime.bloodmagic.api.BloodMagicPlugin) Stopwatch(com.google.common.base.Stopwatch) IBloodMagicPlugin(WayofTime.bloodmagic.api.IBloodMagicPlugin) Pair(org.apache.commons.lang3.tuple.Pair) Nonnull(javax.annotation.Nonnull)

Example 2 with BloodMagicPlugin

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());
}
Also used : IBloodMagicPlugin(WayofTime.bloodmagic.api.IBloodMagicPlugin) BloodMagicPlugin(WayofTime.bloodmagic.api.BloodMagicPlugin) Stopwatch(com.google.common.base.Stopwatch) IBloodMagicPlugin(WayofTime.bloodmagic.api.IBloodMagicPlugin)

Aggregations

BloodMagicPlugin (WayofTime.bloodmagic.api.BloodMagicPlugin)2 IBloodMagicPlugin (WayofTime.bloodmagic.api.IBloodMagicPlugin)2 Stopwatch (com.google.common.base.Stopwatch)2 Nonnull (javax.annotation.Nonnull)1 ASMDataTable (net.minecraftforge.fml.common.discovery.ASMDataTable)1 Pair (org.apache.commons.lang3.tuple.Pair)1