Test execution and injection

This commit is contained in:
Hugo Manrique
2021-06-07 14:13:32 +02:00
parent ff506dfdf8
commit d429d8383d
11 changed files with 487 additions and 21 deletions

View File

@@ -89,6 +89,8 @@ public final class CommandGraphInjector<S> {
VelocityCommands.getArgumentsNode(asLiteral);
if (argsNode == null) {
// This literal is associated to a BrigadierCommand, filter normally
// TODO Document alias redirects are not supported, see
// CommandGraphInjectorTests#testBrigadierCommandAliasRedirectsNotAllowed.
this.copyChildren(node, copy, source);
} else {
// Copy all children nodes (arguments node and hints)

View File

@@ -97,6 +97,7 @@ public class VelocityCommandManager implements CommandManager {
public void register(final CommandMeta meta, final Command command) {
Preconditions.checkNotNull(meta, "meta");
Preconditions.checkNotNull(command, "command");
// TODO This is quite ugly; find registrar and then attempt registering.
for (final CommandRegistrar<?> registrar : this.registrars) {
if (this.tryRegister(registrar, command, meta)) {
@@ -114,7 +115,7 @@ public class VelocityCommandManager implements CommandManager {
return false;
}
try {
registrar.register(superInterface.cast(command), meta);
registrar.register(meta, superInterface.cast(command));
return true;
} catch (final IllegalArgumentException ignored) {
return false;

View File

@@ -35,7 +35,7 @@ public final class BrigadierCommandRegistrar extends AbstractCommandRegistrar<Br
}
@Override
public void register(final BrigadierCommand command, final CommandMeta meta) {
public void register(final CommandMeta meta, final BrigadierCommand command) {
// The literal name might not match any aliases on the given meta.
// Register it (if valid), since it's probably what the user expects.
// If invalid, the metadata contains the same alias, but in lowercase.

View File

@@ -33,15 +33,15 @@ public interface CommandRegistrar<T extends Command> {
/**
* Registers the given command.
*
* @param command the command to register
* @param meta the command metadata, including the case-insensitive aliases
* @param command the command to register
* @throws IllegalArgumentException if the given command cannot be registered
*/
void register(final T command, final CommandMeta meta);
void register(final CommandMeta meta, final T command);
/**
* Returns the superclass or superinterface of all {@link Command} classes
* compatible with this registrar. Note that {@link #register(Command, CommandMeta)}
* compatible with this registrar. Note that {@link #register(CommandMeta, Command)}
* may impose additional restrictions on individual {@link Command} instances.
*
* @return the superclass of all the classes compatible with this registrar

View File

@@ -56,7 +56,7 @@ abstract class InvocableCommandRegistrar<T extends InvocableCommand<I>,
}
@Override
public void register(final T command, final CommandMeta meta) {
public void register(final CommandMeta meta, final T command) {
final Iterator<String> aliases = meta.getAliases().iterator();
final String primaryAlias = aliases.next();