Search in sources :

Example 1 with HelpCommand

use of com.freya02.botcommands.internal.prefixed.HelpCommand in project BotCommands by freya022.

the class CommandsBuilderImpl method buildClasses.

private void buildClasses() throws Exception {
    classes.removeIf(c -> {
        try {
            return !ReflectionUtils.isInstantiable(c);
        } catch (IllegalAccessException | InvocationTargetException e) {
            LOGGER.error("An error occurred while trying to find if a class is instantiable", e);
            throw new RuntimeException("An error occurred while trying to find if a class is instantiable", e);
        }
    });
    for (Class<?> aClass : classes) {
        processClass(aClass);
    }
    if (!context.isHelpDisabled()) {
        processClass(HelpCommand.class);
        final TextCommandInfo helpInfo = context.findFirstCommand(CommandPath.of("help"));
        if (helpInfo == null)
            throw new IllegalStateException("HelpCommand did not build properly");
        final HelpCommand help = (HelpCommand) helpInfo.getInstance();
        help.generate();
    }
    prefixedCommandsBuilder.postProcess();
    if (context.getComponentManager() != null) {
        // Load button listeners
        for (Class<?> aClass : classes) {
            componentsBuilder.processClass(aClass);
        }
    } else {
        LOGGER.info("ComponentManager is not set, the Components API, paginators and menus won't be usable");
    }
    applicationCommandsBuilder.postProcess();
    if (context.getComponentManager() != null) {
        componentsBuilder.postProcess();
    }
    eventListenersBuilder.postProcess();
    autocompletionHandlersBuilder.postProcess();
    context.getRegistrationListeners().forEach(RegistrationListener::onBuildComplete);
    LOGGER.info("Finished registering all commands");
}
Also used : RegistrationListener(com.freya02.botcommands.api.RegistrationListener) HelpCommand(com.freya02.botcommands.internal.prefixed.HelpCommand) TextCommandInfo(com.freya02.botcommands.internal.prefixed.TextCommandInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

RegistrationListener (com.freya02.botcommands.api.RegistrationListener)1 HelpCommand (com.freya02.botcommands.internal.prefixed.HelpCommand)1 TextCommandInfo (com.freya02.botcommands.internal.prefixed.TextCommandInfo)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1