Search in sources :

Example 1 with TextSubcommandCandidates

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

the class BContextImpl method addTextCommand.

public void addTextCommand(TextCommandInfo commandInfo) {
    final CommandPath path = commandInfo.getPath();
    final List<CommandPath> aliases = commandInfo.getAliases();
    textCommandMap.compute(path, (k, v) -> {
        if (v == null)
            return new TextCommandCandidates(commandInfo);
        else
            v.add(commandInfo);
        return v;
    });
    final CommandPath parentPath = path.getParent();
    if (parentPath != null) {
        // Add subcommands to cache
        // If subcommands candidates exist, append, if not then create
        textSubcommandsMap.compute(parentPath, (x, candidates) -> (candidates == null) ? new TextSubcommandCandidates(commandInfo) : candidates.addSubcommand(commandInfo));
    }
    for (CommandPath alias : aliases) {
        textCommandMap.compute(alias, (k, v) -> {
            if (v == null)
                return new TextCommandCandidates(commandInfo);
            else
                v.add(commandInfo);
            return v;
        });
    }
}
Also used : TextSubcommandCandidates(com.freya02.botcommands.internal.prefixed.TextSubcommandCandidates) TextCommandCandidates(com.freya02.botcommands.internal.prefixed.TextCommandCandidates) CommandPath(com.freya02.botcommands.api.application.CommandPath)

Aggregations

CommandPath (com.freya02.botcommands.api.application.CommandPath)1 TextCommandCandidates (com.freya02.botcommands.internal.prefixed.TextCommandCandidates)1 TextSubcommandCandidates (com.freya02.botcommands.internal.prefixed.TextSubcommandCandidates)1