Search in sources :

Example 1 with BannerPrinter

use of net.kodehawa.mantarobot.utils.banner.BannerPrinter in project MantaroBot by Mantaro.

the class MantaroCore method startMainComponents.

public MantaroCore startMainComponents(boolean single) throws Exception {
    if (config == null)
        throw new IllegalArgumentException("Config cannot be null!");
    if (useSentry)
        Sentry.init(config.sentryDSN);
    if (useBanner)
        new BannerPrinter(1).printBanner();
    if (commandsPackage == null)
        throw new IllegalArgumentException("Cannot look for commands if you don't specify where!");
    if (optsPackage == null)
        throw new IllegalArgumentException("Cannot look for options if you don't specify where!");
    Future<Set<Class<?>>> commands = lookForAnnotatedOn(commandsPackage, Module.class);
    Future<Set<Class<?>>> options = lookForAnnotatedOn(optsPackage, Option.class);
    if (single) {
        startSingleShardInstance();
    } else {
        startShardedInstance();
    }
    shardEventBus = new EventBus();
    for (Class<?> aClass : commands.get()) {
        try {
            shardEventBus.register(aClass.newInstance());
        } catch (Exception e) {
            log.error("Invalid module: no zero arg public constructor found for " + aClass);
        }
    }
    for (Class<?> clazz : options.get()) {
        try {
            shardEventBus.register(clazz.newInstance());
        } catch (Exception e) {
            log.error("Invalid module: no zero arg public constructor found for " + clazz);
        }
    }
    Async.thread("Mantaro EventBus-Post", () -> {
        // For now, only used by AsyncInfoMonitor startup and Anime Login Task.
        shardEventBus.post(new PreLoadEvent());
        // Registers all commands
        shardEventBus.post(DefaultCommandProcessor.REGISTRY);
        // Registers all options
        shardEventBus.post(new OptionRegistryEvent());
    });
    return this;
}
Also used : Set(java.util.Set) OptionRegistryEvent(net.kodehawa.mantarobot.options.event.OptionRegistryEvent) BannerPrinter(net.kodehawa.mantarobot.utils.banner.BannerPrinter) EventBus(com.google.common.eventbus.EventBus) PreLoadEvent(net.kodehawa.mantarobot.core.listeners.events.PreLoadEvent)

Aggregations

EventBus (com.google.common.eventbus.EventBus)1 Set (java.util.Set)1 PreLoadEvent (net.kodehawa.mantarobot.core.listeners.events.PreLoadEvent)1 OptionRegistryEvent (net.kodehawa.mantarobot.options.event.OptionRegistryEvent)1 BannerPrinter (net.kodehawa.mantarobot.utils.banner.BannerPrinter)1