Add support for Commodore mappings

This commit is contained in:
Alexander Söderberg 2020-09-20 16:44:30 +02:00
parent b80e33503f
commit 1c831a3bcf
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
13 changed files with 320 additions and 42 deletions

View file

@ -72,11 +72,11 @@ public abstract class CommandManager<C> {
private final Map<Class<? extends Exception>, BiConsumer<C, ? extends Exception>> exceptionHandlers = Maps.newHashMap();
private final CommandExecutionCoordinator<C> commandExecutionCoordinator;
private final CommandRegistrationHandler commandRegistrationHandler;
private final CommandTree<C> commandTree;
private CommandSyntaxFormatter<C> commandSyntaxFormatter = new StandardCommandSyntaxFormatter<>();
private CommandSuggestionProcessor<C> commandSuggestionProcessor = new FilteringCommandSuggestionProcessor<>();
private CommandRegistrationHandler commandRegistrationHandler;
/**
* Create a new command manager instance
@ -87,7 +87,7 @@ public abstract class CommandManager<C> {
public CommandManager(
@Nonnull final Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
@Nonnull final CommandRegistrationHandler commandRegistrationHandler) {
this.commandTree = CommandTree.newTree(this, commandRegistrationHandler);
this.commandTree = CommandTree.newTree(this);
this.commandExecutionCoordinator = commandExecutionCoordinator.apply(commandTree);
this.commandRegistrationHandler = commandRegistrationHandler;
this.servicePipeline.registerServiceType(new TypeToken<CommandPreprocessor<C>>() {
@ -388,4 +388,8 @@ public abstract class CommandManager<C> {
Optional.ofNullable(this.getExceptionHandler(clazz)).orElse(defaultHandler).accept(sender, exception);
}
protected final void setCommandRegistrationHandler(@Nonnull final CommandRegistrationHandler commandRegistrationHandler) {
this.commandRegistrationHandler = commandRegistrationHandler;
}
}

View file

@ -34,7 +34,6 @@ import com.intellectualsites.commands.exceptions.InvalidSyntaxException;
import com.intellectualsites.commands.exceptions.NoCommandInLeafException;
import com.intellectualsites.commands.exceptions.NoPermissionException;
import com.intellectualsites.commands.exceptions.NoSuchCommandException;
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -63,27 +62,21 @@ public final class CommandTree<C> {
private final Node<CommandArgument<C, ?>> internalTree = new Node<>(null);
private final CommandManager<C> commandManager;
private final CommandRegistrationHandler commandRegistrationHandler;
private CommandTree(@Nonnull final CommandManager<C> commandManager,
@Nonnull final CommandRegistrationHandler commandRegistrationHandler) {
private CommandTree(@Nonnull final CommandManager<C> commandManager) {
this.commandManager = commandManager;
this.commandRegistrationHandler = commandRegistrationHandler;
}
/**
* Create a new command tree instance
*
* @param commandManager Command manager
* @param commandRegistrationHandler Command registration handler
* @param <C> Command sender type
* @return New command tree
*/
@Nonnull
public static <C> CommandTree<C> newTree(
@Nonnull final CommandManager<C> commandManager,
@Nonnull final CommandRegistrationHandler commandRegistrationHandler) {
return new CommandTree<>(commandManager, commandRegistrationHandler);
public static <C> CommandTree<C> newTree(@Nonnull final CommandManager<C> commandManager) {
return new CommandTree<>(commandManager);
}
/**
@ -432,7 +425,7 @@ public final class CommandTree<C> {
throw new NoCommandInLeafException(leaf);
} else {
final Command<C> owningCommand = leaf.getOwningCommand();
this.commandRegistrationHandler.registerCommand(owningCommand);
this.commandManager.getCommandRegistrationHandler().registerCommand(owningCommand);
}
});