use of com.freya02.botcommands.api.components.ComponentManager in project BotCommands by freya022.
the class PersistentSelectionMenuBuilder method build.
@NotNull
@Override
public SelectMenu build() {
final ComponentManager componentManager = Utils.getComponentManager(context);
setId(componentManager.putPersistentSelectMenu(this));
return super.build();
}
use of com.freya02.botcommands.api.components.ComponentManager 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");
}
use of com.freya02.botcommands.api.components.ComponentManager in project BotCommands by freya022.
the class BasicPagination method cleanup.
/**
* Cleans up the button IDs used in this paginator
* <br>This will remove every stored button IDs, even then buttons you included yourself
*
* @param context The {@link BContext} of this bot
*/
public void cleanup(BContext context) {
final ComponentManager manager = Utils.getComponentManager(context);
final int deletedIds = manager.deleteIds(usedIds);
LOGGER.trace("Cleaned up {} component IDs out of {}", deletedIds, usedIds.size());
usedIds.clear();
}
use of com.freya02.botcommands.api.components.ComponentManager in project BotCommands by freya022.
the class LambdaSelectionMenuBuilder method build.
@NotNull
@Override
public SelectMenu build() {
final ComponentManager componentManager = Utils.getComponentManager(context);
setId(componentManager.putLambdaSelectMenu(this));
return super.build();
}
Aggregations