use of org.spongepowered.api.command.manager.CommandMapping in project SpongeCommon by SpongePowered.
the class BrigadierCommandRegistrar method registerInternal.
private Tuple<CommandMapping, LiteralCommandNode<CommandSourceStack>> registerInternal(final CommandRegistrar<?> registrar, @Nullable final PluginContainer container, final LiteralCommandNode<CommandSourceStack> namespacedCommand, final String[] secondaryAliases, final boolean allowDuplicates) {
// Brig technically allows them...
// Get the builder and the first literal.
final String requestedAlias = namespacedCommand.getLiteral();
final Optional<CommandMapping> existingMapping = this.manager.commandMapping(requestedAlias);
if (allowDuplicates && existingMapping.isPresent()) {
// then we just let it go, the requirements will be of the old node.
this.dispatcher.register(namespacedCommand);
return Tuple.of(existingMapping.get(), namespacedCommand);
}
// This will throw an error if there is an issue.
final CommandMapping mapping = this.manager.registerNamespacedAlias(registrar, container, namespacedCommand, secondaryAliases);
// Let the registration happen.
this.dispatcher.register(namespacedCommand);
// Redirect aliases
for (final String alias : mapping.allAliases()) {
if (!alias.equals(namespacedCommand.getLiteral())) {
final LiteralArgumentBuilder<CommandSourceStack> redirecting = LiteralArgumentBuilder.<CommandSourceStack>literal(alias).executes(namespacedCommand.getCommand()).requires(namespacedCommand.getRequirement());
if (namespacedCommand.getRedirect() == null) {
redirecting.redirect(namespacedCommand);
} else {
// send it directly to the namespaced command's target.
redirecting.forward(namespacedCommand.getRedirect(), namespacedCommand.getRedirectModifier(), namespacedCommand.isFork());
}
this.dispatcher.register(redirecting.build());
}
}
return Tuple.of(mapping, namespacedCommand);
}
use of org.spongepowered.api.command.manager.CommandMapping in project SpongeCommon by SpongePowered.
the class SpongeRawCommandRegistrar method register.
@Override
public CommandMapping register(@NonNull final PluginContainer container, final Command.@NonNull Raw command, @NonNull final String primaryAlias, @NonNull final String@NonNull ... secondaryAliases) throws CommandFailedRegistrationException {
final CommandMapping mapping = this.manager.registerAlias(this, container, command.commandTree(), primaryAlias, secondaryAliases);
this.commands.put(mapping, command);
return mapping;
}
Aggregations