use of dev.triumphteam.cmd.core.execution.ExecutionProvider in project triumph-cmds by TriumphTeam.
the class BukkitCommand method addSubCommands.
/**
* adds SubCommands from the Command.
*
* @param baseCommand The {@link BaseCommand} to get the sub commands from.
*/
@Override
public void addSubCommands(@NotNull final BaseCommand baseCommand) {
for (final Method method : baseCommand.getClass().getDeclaredMethods()) {
if (Modifier.isPrivate(method.getModifiers()))
continue;
final BukkitSubCommandProcessor<S> processor = new BukkitSubCommandProcessor<>(baseCommand, getName(), method, registries, senderValidator);
final String subCommandName = processor.getName();
if (subCommandName == null)
continue;
final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider;
final BukkitSubCommand<S> subCommand = subCommands.computeIfAbsent(subCommandName, it -> new BukkitSubCommand<>(processor, getName(), executionProvider));
processor.getAlias().forEach(alias -> subCommandAliases.putIfAbsent(alias, subCommand));
}
}
use of dev.triumphteam.cmd.core.execution.ExecutionProvider in project triumph-cmds by TriumphTeam.
the class CliCommand method addSubCommands.
/**
* adds SubCommands from the Command.
*
* @param baseCommand The {@link BaseCommand} to get the sub commands from.
*/
@Override
public void addSubCommands(@NotNull final BaseCommand baseCommand) {
for (final Method method : baseCommand.getClass().getDeclaredMethods()) {
if (Modifier.isPrivate(method.getModifiers()))
continue;
final CliSubCommandProcessor<S> processor = new CliSubCommandProcessor<>(baseCommand, name, method, registries, senderValidator);
final String subCommandName = processor.getName();
if (subCommandName == null)
continue;
final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider;
final CliSubCommand<S> subCommand = subCommands.computeIfAbsent(subCommandName, it -> new CliSubCommand<>(processor, name, executionProvider));
processor.getAlias().forEach(alias -> subCommandAliases.putIfAbsent(alias, subCommand));
}
}
use of dev.triumphteam.cmd.core.execution.ExecutionProvider in project triumph-cmds by TriumphTeam.
the class PrefixedCommand method addSubCommands.
/**
* {@inheritDoc}
*/
@Override
public void addSubCommands(@NotNull final BaseCommand baseCommand) {
for (final Method method : baseCommand.getClass().getDeclaredMethods()) {
final PrefixedSubCommandProcessor<S> processor = new PrefixedSubCommandProcessor<>(baseCommand, name, method, registries, senderValidator);
final String subCommandName = processor.getName();
if (subCommandName == null)
continue;
final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider;
final PrefixedSubCommand<S> subCommand = subCommands.computeIfAbsent(subCommandName, s -> new PrefixedSubCommand<>(processor, name, executionProvider));
for (final String alias : processor.getAlias()) {
subCommands.putIfAbsent(alias, subCommand);
}
}
}
use of dev.triumphteam.cmd.core.execution.ExecutionProvider in project triumph-cmds by TriumphTeam.
the class SlashCommand method addSubCommands.
/**
* {@inheritDoc}
*/
@Override
public void addSubCommands(@NotNull final BaseCommand baseCommand) {
for (final Method method : baseCommand.getClass().getDeclaredMethods()) {
if (Modifier.isPrivate(method.getModifiers()))
continue;
final SlashSubCommandProcessor<S> processor = new SlashSubCommandProcessor<>(baseCommand, name, method, registries, choiceRegistry, senderValidator);
final String subCommandName = processor.getName();
if (subCommandName == null)
continue;
// TODO: 11/27/2021 Remove repeating code for throwing the exception.
if (isDefault) {
throw new CommandRegistrationException("Default commands cannot be registered with subcommands", baseCommand.getClass());
}
if (processor.isDefault()) {
if (subCommands.size() > 0) {
throw new CommandRegistrationException("Default commands cannot be registered with subcommands", baseCommand.getClass());
}
isDefault = true;
}
final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider;
subCommands.putIfAbsent(subCommandName, new SlashSubCommand<>(processor, name, executionProvider));
}
}
Aggregations