chore(core): deprecate prefixed accessors/mutators in CommandManager (#377)
chore(core): deprecate prefixed accessors/mutators in CommandManager.java All prefixed (actual) getters/setters in CommandManager have been deprecated, and non-prefixed alternatives have been introduced. I've also put some effort into improving the JavaDocs of these methods.
This commit is contained in:
parent
687cd4c536
commit
296539d56c
48 changed files with 400 additions and 157 deletions
|
|
@ -61,7 +61,7 @@ public final class CommandHelpHandler<C> {
|
|||
*/
|
||||
public @NonNull List<@NonNull VerboseHelpEntry<C>> getAllCommands() {
|
||||
final List<VerboseHelpEntry<C>> syntaxHints = new ArrayList<>();
|
||||
for (final Command<C> command : this.commandManager.getCommands()) {
|
||||
for (final Command<C> command : this.commandManager.commands()) {
|
||||
/* Check command is not filtered */
|
||||
if (!this.commandPredicate.test(command)) {
|
||||
continue;
|
||||
|
|
@ -71,7 +71,7 @@ public final class CommandHelpHandler<C> {
|
|||
final String description = command.getCommandMeta().getOrDefault(CommandMeta.DESCRIPTION, "");
|
||||
syntaxHints.add(new VerboseHelpEntry<>(
|
||||
command,
|
||||
this.commandManager.getCommandSyntaxFormatter()
|
||||
this.commandManager.commandSyntaxFormatter()
|
||||
.apply(arguments, null),
|
||||
description
|
||||
));
|
||||
|
|
@ -89,10 +89,10 @@ public final class CommandHelpHandler<C> {
|
|||
*/
|
||||
public @NonNull List<@NonNull String> getLongestSharedChains() {
|
||||
final List<String> chains = new ArrayList<>();
|
||||
this.commandManager.getCommandTree().getRootNodes().forEach(node ->
|
||||
this.commandManager.commandTree().getRootNodes().forEach(node ->
|
||||
chains.add(Objects.requireNonNull(node.getValue())
|
||||
.getName() + this.commandManager
|
||||
.getCommandSyntaxFormatter()
|
||||
.commandSyntaxFormatter()
|
||||
.apply(
|
||||
Collections
|
||||
.emptyList(),
|
||||
|
|
@ -179,7 +179,7 @@ public final class CommandHelpHandler<C> {
|
|||
final String description = command.getCommandMeta().getOrDefault(CommandMeta.DESCRIPTION, "");
|
||||
syntaxHints.add(new VerboseHelpEntry<>(
|
||||
command,
|
||||
this.commandManager.getCommandSyntaxFormatter()
|
||||
this.commandManager.commandSyntaxFormatter()
|
||||
.apply(arguments, null),
|
||||
description
|
||||
));
|
||||
|
|
@ -191,7 +191,7 @@ public final class CommandHelpHandler<C> {
|
|||
}
|
||||
|
||||
/* Traverse command to find the most specific help topic */
|
||||
final CommandTree.Node<CommandArgument<C, ?>> node = this.commandManager.getCommandTree()
|
||||
final CommandTree.Node<CommandArgument<C, ?>> node = this.commandManager.commandTree()
|
||||
.getNamedNode(availableCommandLabels.iterator().next());
|
||||
|
||||
final List<CommandArgument<C, ?>> traversedNodes = new LinkedList<>();
|
||||
|
|
@ -240,7 +240,7 @@ public final class CommandHelpHandler<C> {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
final String currentDescription = this.commandManager.getCommandSyntaxFormatter().apply(traversedNodes, null);
|
||||
final String currentDescription = this.commandManager.commandSyntaxFormatter().apply(traversedNodes, null);
|
||||
/* Attempt to parse the longest possible description for the children */
|
||||
final List<String> childSuggestions = new LinkedList<>();
|
||||
for (final CommandTree.Node<CommandArgument<C, ?>> child : head.getChildren()) {
|
||||
|
|
@ -258,7 +258,7 @@ public final class CommandHelpHandler<C> {
|
|||
child.getValue().getOwningCommand().getCommandPermission()
|
||||
)) {
|
||||
traversedNodesSub.add(child.getValue());
|
||||
childSuggestions.add(this.commandManager.getCommandSyntaxFormatter().apply(traversedNodesSub, child));
|
||||
childSuggestions.add(this.commandManager.commandSyntaxFormatter().apply(traversedNodesSub, child));
|
||||
}
|
||||
}
|
||||
return new MultiHelpTopic<>(currentDescription, childSuggestions);
|
||||
|
|
|
|||
|
|
@ -256,6 +256,7 @@ public abstract class CommandManager<C> {
|
|||
*
|
||||
* @return the caption variable replacement handler
|
||||
* @since 1.7.0
|
||||
* @see #captionVariableReplacementHandler(CaptionVariableReplacementHandler)
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public @NonNull CaptionVariableReplacementHandler captionVariableReplacementHandler() {
|
||||
|
|
@ -267,6 +268,7 @@ public abstract class CommandManager<C> {
|
|||
*
|
||||
* @param captionVariableReplacementHandler new replacement handler
|
||||
* @since 1.7.0
|
||||
* @see #captionVariableReplacementHandler()
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public void captionVariableReplacementHandler(
|
||||
|
|
@ -279,8 +281,23 @@ public abstract class CommandManager<C> {
|
|||
* Get the command syntax formatter
|
||||
*
|
||||
* @return Command syntax formatter
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed getter {@link #commandSyntaxFormatter()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public @NonNull CommandSyntaxFormatter<C> getCommandSyntaxFormatter() {
|
||||
return this.commandSyntaxFormatter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command syntax formatter.
|
||||
*
|
||||
* @return the syntax formatter
|
||||
* @since 1.7.0
|
||||
* @see #commandSyntaxFormatter(CommandSyntaxFormatter)
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public @NonNull CommandSyntaxFormatter<C> commandSyntaxFormatter() {
|
||||
return this.commandSyntaxFormatter;
|
||||
}
|
||||
|
||||
|
|
@ -288,8 +305,26 @@ public abstract class CommandManager<C> {
|
|||
* Set the command syntax formatter
|
||||
*
|
||||
* @param commandSyntaxFormatter New formatter
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed setter {@link #commandSyntaxFormatter(CommandSyntaxFormatter)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public void setCommandSyntaxFormatter(final @NonNull CommandSyntaxFormatter<C> commandSyntaxFormatter) {
|
||||
this.commandSyntaxFormatter(commandSyntaxFormatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command syntax formatter.
|
||||
* <p>
|
||||
* The command syntax formatter is used to format the command syntax hints that are used in help and error messages.
|
||||
*
|
||||
* @param commandSyntaxFormatter new formatter
|
||||
* @since 1.7.0
|
||||
* @see #commandSyntaxFormatter()
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public void commandSyntaxFormatter(final @NonNull CommandSyntaxFormatter<C> commandSyntaxFormatter) {
|
||||
this.commandSyntaxFormatter = commandSyntaxFormatter;
|
||||
}
|
||||
|
||||
|
|
@ -297,16 +332,49 @@ public abstract class CommandManager<C> {
|
|||
* Get the command registration handler
|
||||
*
|
||||
* @return Command registration handler
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed getter {@link #commandRegistrationHandler()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public @NonNull CommandRegistrationHandler getCommandRegistrationHandler() {
|
||||
return this.commandRegistrationHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command registration handler.
|
||||
* <p>
|
||||
* The command registration handler is able to intercept newly created/deleted commands, in order to propagate
|
||||
* these changes to the native command handler of the platform.
|
||||
* <p>
|
||||
* In platforms without a native command concept, this is likely to return
|
||||
* {@link CommandRegistrationHandler#nullCommandRegistrationHandler()}.
|
||||
*
|
||||
* @return the command registration handler
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public @NonNull CommandRegistrationHandler commandRegistrationHandler() {
|
||||
return this.commandRegistrationHandler;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
protected final void setCommandRegistrationHandler(final @NonNull CommandRegistrationHandler commandRegistrationHandler) {
|
||||
this.commandRegistrationHandler(commandRegistrationHandler);
|
||||
}
|
||||
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
protected final void commandRegistrationHandler(final @NonNull CommandRegistrationHandler commandRegistrationHandler) {
|
||||
this.requireState(RegistrationState.BEFORE_REGISTRATION);
|
||||
this.commandRegistrationHandler = commandRegistrationHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given {@code capability}.
|
||||
*
|
||||
* @param capability the capability
|
||||
* @since 1.7.0
|
||||
* @see #hasCapability(CloudCapability)
|
||||
* @see #capabilities()
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
protected final void registerCapability(final @NonNull CloudCapability capability) {
|
||||
|
|
@ -319,6 +387,7 @@ public abstract class CommandManager<C> {
|
|||
* @param capability the capability
|
||||
* @return {@code true} if the implementation has the {@code capability}, {@code false} if not
|
||||
* @since 1.7.0
|
||||
* @see #capabilities()
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public boolean hasCapability(final @NonNull CloudCapability capability) {
|
||||
|
|
@ -330,17 +399,13 @@ public abstract class CommandManager<C> {
|
|||
*
|
||||
* @return the currently registered capabilities
|
||||
* @since 1.7.0
|
||||
* @see #hasCapability(CloudCapability)
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public @NonNull Collection<@NonNull CloudCapability> capabilities() {
|
||||
return Collections.unmodifiableSet(new HashSet<>(this.capabilities));
|
||||
}
|
||||
|
||||
protected final void setCommandRegistrationHandler(final @NonNull CommandRegistrationHandler commandRegistrationHandler) {
|
||||
this.requireState(RegistrationState.BEFORE_REGISTRATION);
|
||||
this.commandRegistrationHandler = commandRegistrationHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the command sender has the required permission. If the permission node is
|
||||
* empty, this should return {@code true}
|
||||
|
|
@ -384,8 +449,23 @@ public abstract class CommandManager<C> {
|
|||
* Get the caption registry
|
||||
*
|
||||
* @return Caption registry
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed getter {@link #captionRegistry()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public final @NonNull CaptionRegistry<C> getCaptionRegistry() {
|
||||
return this.captionRegistry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the caption registry.
|
||||
*
|
||||
* @return the caption registry
|
||||
* @since 1.7.0
|
||||
* @see #captionRegistry(CaptionRegistry)
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public final @NonNull CaptionRegistry<C> captionRegistry() {
|
||||
return this.captionRegistry;
|
||||
}
|
||||
|
||||
|
|
@ -394,8 +474,26 @@ public abstract class CommandManager<C> {
|
|||
* and so you may need to insert these captions yourself if you do decide to replace the caption registry.
|
||||
*
|
||||
* @param captionRegistry New caption registry
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed setter {@link #captionRegistry(CaptionRegistry)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public final void setCaptionRegistry(final @NonNull CaptionRegistry<C> captionRegistry) {
|
||||
this.captionRegistry(captionRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the caption registry.
|
||||
* <p>
|
||||
* Some platforms may inject their own captions into the default caption registry,
|
||||
* and so you may need to insert these captions yourself, if you do decide to replace the caption registry.
|
||||
*
|
||||
* @param captionRegistry new caption registry.
|
||||
* @see #captionRegistry()
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public final void captionRegistry(final @NonNull CaptionRegistry<C> captionRegistry) {
|
||||
this.captionRegistry = captionRegistry;
|
||||
}
|
||||
|
||||
|
|
@ -403,7 +501,7 @@ public abstract class CommandManager<C> {
|
|||
* Replace the default caption registry
|
||||
*
|
||||
* @param captionRegistry Caption registry to use
|
||||
* @deprecated Use {@link #setCaptionRegistry(CaptionRegistry)} These methods are identical.
|
||||
* @deprecated Use {@link #captionRegistry(CaptionRegistry)} These methods are identical.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED)
|
||||
|
|
@ -782,8 +880,25 @@ public abstract class CommandManager<C> {
|
|||
* are doing
|
||||
*
|
||||
* @return Command tree
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed getter {@link #commandTree()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public @NonNull CommandTree<C> getCommandTree() {
|
||||
return this.commandTree();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal command tree.
|
||||
* <p>
|
||||
* Be careful when accessing the command tree. Do not interact with it, unless you
|
||||
* absolutely know what you're doing.
|
||||
*
|
||||
* @return the command tree
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public @NonNull CommandTree<C> commandTree() {
|
||||
return this.commandTree;
|
||||
}
|
||||
|
||||
|
|
@ -871,9 +986,24 @@ public abstract class CommandManager<C> {
|
|||
* Get the command suggestions processor instance currently used in this command manager
|
||||
*
|
||||
* @return Command suggestions processor
|
||||
* @see #setCommandSuggestionProcessor(CommandSuggestionProcessor) Setting the suggestion processor
|
||||
* @see #commandSuggestionProcessor(CommandSuggestionProcessor) Setting the suggestion processor
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed getter {@link #commandSuggestionProcessor()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public @NonNull CommandSuggestionProcessor<C> getCommandSuggestionProcessor() {
|
||||
return this.commandSuggestionProcessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command suggestion processor used in this command manager.
|
||||
*
|
||||
* @return the command suggestion processor
|
||||
* @since 1.7.0
|
||||
* @see #commandSuggestionProcessor(CommandSuggestionProcessor)
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public @NonNull CommandSuggestionProcessor<C> commandSuggestionProcessor() {
|
||||
return this.commandSuggestionProcessor;
|
||||
}
|
||||
|
||||
|
|
@ -883,8 +1013,27 @@ public abstract class CommandManager<C> {
|
|||
* before it's returned to the caller
|
||||
*
|
||||
* @param commandSuggestionProcessor New command suggestions processor
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed setter
|
||||
* {@link #commandSuggestionProcessor(CommandSuggestionProcessor)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public void setCommandSuggestionProcessor(final @NonNull CommandSuggestionProcessor<C> commandSuggestionProcessor) {
|
||||
this.commandSuggestionProcessor(commandSuggestionProcessor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command suggestion processor.
|
||||
* <p>
|
||||
* This will be called ever time {@link #suggest(Object, String)} is called, in order to process the list
|
||||
* of suggestions before it's returned to the caller.
|
||||
*
|
||||
* @param commandSuggestionProcessor the new command sugesstion processor
|
||||
* @since 1.7.0
|
||||
* @see #commandSuggestionProcessor()
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public void commandSuggestionProcessor(final @NonNull CommandSuggestionProcessor<C> commandSuggestionProcessor) {
|
||||
this.commandSuggestionProcessor = commandSuggestionProcessor;
|
||||
}
|
||||
|
||||
|
|
@ -900,8 +1049,31 @@ public abstract class CommandManager<C> {
|
|||
* should be registered in the constructor of the platform {@link CommandManager}
|
||||
*
|
||||
* @return Parser registry instance
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed getter {@link #parserRegistry()} instead.
|
||||
*/
|
||||
public ParserRegistry<C> getParserRegistry() {
|
||||
@Deprecated
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public @NonNull ParserRegistry<C> getParserRegistry() {
|
||||
return this.parserRegistry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parser registry intance.
|
||||
* <p>
|
||||
* The parser registry contains default mappings to {@link ArgumentParser argument parsers} and
|
||||
* allows for the registryion of custom mappings. The parser registry also contains mappings between
|
||||
* annotations and {@link ParserParameter}, which allows for the customization of parser settings by
|
||||
* using annotations.
|
||||
* <p>
|
||||
* When creating a new parser type, it is highly recommended to register it in the parser registry.
|
||||
* In particular, default parser types (shipped with cloud implementations) should be registered in the
|
||||
* constructor of the platform {@link CommandManager}.
|
||||
*
|
||||
* @return the parser registry instance
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public @NonNull ParserRegistry<C> parserRegistry() {
|
||||
return this.parserRegistry;
|
||||
}
|
||||
|
||||
|
|
@ -915,7 +1087,6 @@ public abstract class CommandManager<C> {
|
|||
return this.parameterInjectorRegistry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the exception handler for an exception type, if one has been registered
|
||||
*
|
||||
|
|
@ -974,8 +1145,22 @@ public abstract class CommandManager<C> {
|
|||
* Get a collection containing all registered commands.
|
||||
*
|
||||
* @return Unmodifiable view of all registered commands
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed getter {@link #commands()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public final @NonNull Collection<@NonNull Command<C>> getCommands() {
|
||||
return this.commands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable view of all registered commands.
|
||||
*
|
||||
* @return unmodifiable view of all registered commands
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public final @NonNull Collection<@NonNull Command<C>> commands() {
|
||||
return Collections.unmodifiableCollection(this.commands);
|
||||
}
|
||||
|
||||
|
|
@ -986,8 +1171,26 @@ public abstract class CommandManager<C> {
|
|||
*
|
||||
* @return Command help handler. A new instance will be created
|
||||
* each time this method is called.
|
||||
* @deprecated for removal since 1.7.0. Use {@link #createCommandHelpHandler()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public final @NonNull CommandHelpHandler<C> getCommandHelpHandler() {
|
||||
return this.createCommandHelpHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new command help handler instance.
|
||||
* <p>
|
||||
* The command helper handler can be used to assist in the production of commad help menus, etc.
|
||||
* <p>
|
||||
* This command help handler instance will display all commands registered in this command manager.
|
||||
*
|
||||
* @return a new command helper handler instance
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public final @NonNull CommandHelpHandler<C> createCommandHelpHandler() {
|
||||
return new CommandHelpHandler<>(this, cmd -> true);
|
||||
}
|
||||
|
||||
|
|
@ -1000,9 +1203,32 @@ public abstract class CommandManager<C> {
|
|||
* the help menu.
|
||||
* @return Command help handler. A new instance will be created
|
||||
* each time this method is called.
|
||||
* @deprecated for removal since 1.7.0. Use {@link #createCommandHelpHandler(Predicate)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public final @NonNull CommandHelpHandler<C> getCommandHelpHandler(
|
||||
final @NonNull Predicate<Command<C>> commandPredicate
|
||||
) {
|
||||
return this.createCommandHelpHandler(commandPredicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new command help handler instance.
|
||||
* <p>
|
||||
* The command helper handler can be used to assist in the production of commad help menus, etc.
|
||||
* <p>
|
||||
* A predicate can be specified to filter what commands
|
||||
* registered in this command manager are visible in the help menu.
|
||||
*
|
||||
* @param commandPredicate predicate that filters what commands are displayed in
|
||||
* the help menu.
|
||||
* @return a new command helper handler instance
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public final @NonNull CommandHelpHandler<C> createCommandHelpHandler(
|
||||
final @NonNull Predicate<Command<C>> commandPredicate
|
||||
) {
|
||||
return new CommandHelpHandler<>(this, commandPredicate);
|
||||
}
|
||||
|
|
@ -1102,7 +1328,7 @@ public abstract class CommandManager<C> {
|
|||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.4.0")
|
||||
protected final void lockRegistration() {
|
||||
if (this.getRegistrationState() == RegistrationState.BEFORE_REGISTRATION) {
|
||||
if (this.registrationState() == RegistrationState.BEFORE_REGISTRATION) {
|
||||
this.transitionOrThrow(RegistrationState.BEFORE_REGISTRATION, RegistrationState.AFTER_REGISTRATION);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1116,9 +1342,24 @@ public abstract class CommandManager<C> {
|
|||
*
|
||||
* @return The current state
|
||||
* @since 1.2.0
|
||||
* @deprecated for removal since 1.7.0. Use the non-prefixed getter {@link #registrationState()} instead.
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.2.0")
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public final @NonNull RegistrationState getRegistrationState() {
|
||||
return this.registrationState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the active registration state for this manager.
|
||||
* <p>
|
||||
* If the state is {@link RegistrationState#AFTER_REGISTRATION}, commands can no longer be registered.
|
||||
*
|
||||
* @return the current state
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@API(status = API.Status.STABLE, since = "1.7.0")
|
||||
public final @NonNull RegistrationState registrationState() {
|
||||
return this.state.get();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ public final class CommandTree<C> {
|
|||
} else {
|
||||
/* Too many arguments. We have a unique path, so we can send the entire context */
|
||||
return Pair.of(null, new InvalidSyntaxException(
|
||||
this.commandManager.getCommandSyntaxFormatter()
|
||||
this.commandManager.commandSyntaxFormatter()
|
||||
.apply(parsedArguments, root),
|
||||
commandContext.getSender(), this.getChain(root)
|
||||
.stream()
|
||||
|
|
@ -219,7 +219,7 @@ public final class CommandTree<C> {
|
|||
} else {
|
||||
/* Too many arguments. We have a unique path, so we can send the entire context */
|
||||
return Pair.of(null, new InvalidSyntaxException(
|
||||
this.commandManager.getCommandSyntaxFormatter()
|
||||
this.commandManager.commandSyntaxFormatter()
|
||||
.apply(parsedArguments, root),
|
||||
commandContext.getSender(), this.getChain(root)
|
||||
.stream()
|
||||
|
|
@ -278,7 +278,7 @@ public final class CommandTree<C> {
|
|||
}
|
||||
/* We know that there's no command and we also cannot match any of the children */
|
||||
return Pair.of(null, new InvalidSyntaxException(
|
||||
this.commandManager.getCommandSyntaxFormatter()
|
||||
this.commandManager.commandSyntaxFormatter()
|
||||
.apply(parsedArguments, root),
|
||||
commandContext.getSender(), this.getChain(root)
|
||||
.stream()
|
||||
|
|
@ -378,7 +378,7 @@ public final class CommandTree<C> {
|
|||
}
|
||||
/* Not enough arguments */
|
||||
return Pair.of(null, new InvalidSyntaxException(
|
||||
this.commandManager.getCommandSyntaxFormatter()
|
||||
this.commandManager.commandSyntaxFormatter()
|
||||
.apply(Objects.requireNonNull(
|
||||
child.getValue()
|
||||
.getOwningCommand())
|
||||
|
|
@ -411,7 +411,7 @@ public final class CommandTree<C> {
|
|||
}
|
||||
/* Child does not have a command and so we cannot proceed */
|
||||
return Pair.of(null, new InvalidSyntaxException(
|
||||
this.commandManager.getCommandSyntaxFormatter()
|
||||
this.commandManager.commandSyntaxFormatter()
|
||||
.apply(parsedArguments, root),
|
||||
commandContext.getSender(), this.getChain(root)
|
||||
.stream()
|
||||
|
|
@ -449,7 +449,7 @@ public final class CommandTree<C> {
|
|||
} else {
|
||||
/* Too many arguments. We have a unique path, so we can send the entire context */
|
||||
return Pair.of(null, new InvalidSyntaxException(
|
||||
this.commandManager.getCommandSyntaxFormatter()
|
||||
this.commandManager.commandSyntaxFormatter()
|
||||
.apply(parsedArguments, child),
|
||||
commandContext.getSender(), this.getChain(root)
|
||||
.stream()
|
||||
|
|
@ -778,7 +778,7 @@ public final class CommandTree<C> {
|
|||
throw new NoCommandInLeafException(leaf);
|
||||
} else {
|
||||
final Command<C> owningCommand = leaf.getOwningCommand();
|
||||
this.commandManager.getCommandRegistrationHandler().registerCommand(owningCommand);
|
||||
this.commandManager.commandRegistrationHandler().registerCommand(owningCommand);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -699,7 +699,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>,
|
|||
*/
|
||||
public @NonNull CommandArgument<@NonNull C, @NonNull T> build() {
|
||||
if (this.parser == null && this.manager != null) {
|
||||
this.parser = this.manager.getParserRegistry().createParser(this.valueType, ParserParameters.empty())
|
||||
this.parser = this.manager.parserRegistry().createParser(this.valueType, ParserParameters.empty())
|
||||
.orElse(null);
|
||||
}
|
||||
if (this.parser == null) {
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public final class DelegatingCommandSuggestionEngine<C> implements CommandSugges
|
|||
context.store("__raw_input__", new LinkedList<>(inputQueue));
|
||||
final List<String> suggestions;
|
||||
if (this.commandManager.preprocessContext(context, inputQueue) == State.ACCEPTED) {
|
||||
suggestions = this.commandManager.getCommandSuggestionProcessor().apply(
|
||||
suggestions = this.commandManager.commandSuggestionProcessor().apply(
|
||||
new CommandPreprocessingContext<>(context, inputQueue),
|
||||
this.commandTree.getSuggestions(
|
||||
context,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public final class DelegatingCommandSuggestionEngineFactory<C> {
|
|||
*/
|
||||
public DelegatingCommandSuggestionEngineFactory(final @NonNull CommandManager<C> commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
this.commandTree = commandManager.getCommandTree();
|
||||
this.commandTree = commandManager.commandTree();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
|
|||
final @NonNull Pair<@NonNull Class<U>,
|
||||
@NonNull Class<V>> types
|
||||
) {
|
||||
final ParserRegistry<C> parserRegistry = manager.getParserRegistry();
|
||||
final ParserRegistry<C> parserRegistry = manager.parserRegistry();
|
||||
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(
|
||||
TypeToken.get(types.getFirst()),
|
||||
ParserParameters.empty()
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
|
|||
final @NonNull Triplet<@NonNull String, @NonNull String, @NonNull String> names,
|
||||
final @NonNull Triplet<@NonNull Class<U>, @NonNull Class<V>, @NonNull Class<W>> types
|
||||
) {
|
||||
final ParserRegistry<C> parserRegistry = manager.getParserRegistry();
|
||||
final ParserRegistry<C> parserRegistry = manager.parserRegistry();
|
||||
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(
|
||||
TypeToken.get(types.getFirst()),
|
||||
ParserParameters.empty()
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ public class CommandContext<C> {
|
|||
this.commandSender = commandSender;
|
||||
this.suggestions = suggestions;
|
||||
this.commandManager = commandManager;
|
||||
this.captionRegistry = commandManager.getCaptionRegistry();
|
||||
this.captionRegistry = commandManager.captionRegistry();
|
||||
this.captionVariableReplacementHandler = commandManager.captionVariableReplacementHandler();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class CommandDeletionTest {
|
|||
assertThat(completionException).hasCauseThat().isInstanceOf(NoSuchCommandException.class);
|
||||
|
||||
assertThat(this.commandManager.suggest(new TestCommandSender(), "")).isEmpty();
|
||||
assertThat(this.commandManager.getCommandTree().getRootNodes()).isEmpty();
|
||||
assertThat(this.commandManager.commandTree().getRootNodes()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -144,6 +144,6 @@ class CommandDeletionTest {
|
|||
verifyNoMoreInteractions(handler2);
|
||||
verifyNoMoreInteractions(handler3);
|
||||
|
||||
assertThat(this.commandManager.getCommandTree().getRootNodes()).isEmpty();
|
||||
assertThat(this.commandManager.commandTree().getRootNodes()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class CommandHelpHandlerTest {
|
|||
@Test
|
||||
void testVerboseHelp() {
|
||||
final List<CommandHelpHandler.VerboseHelpEntry<TestCommandSender>> syntaxHints
|
||||
= manager.getCommandHelpHandler().getAllCommands();
|
||||
= manager.createCommandHelpHandler().getAllCommands();
|
||||
final CommandHelpHandler.VerboseHelpEntry<TestCommandSender> entry0 = syntaxHints.get(0);
|
||||
Assertions.assertEquals("test <potato>", entry0.getSyntaxString());
|
||||
final CommandHelpHandler.VerboseHelpEntry<TestCommandSender> entry1 = syntaxHints.get(1);
|
||||
|
|
@ -84,22 +84,22 @@ class CommandHelpHandlerTest {
|
|||
|
||||
@Test
|
||||
void testLongestChains() {
|
||||
final List<String> longestChains = manager.getCommandHelpHandler().getLongestSharedChains();
|
||||
final List<String> longestChains = manager.createCommandHelpHandler().getLongestSharedChains();
|
||||
Assertions.assertEquals(Arrays.asList("test int|this|<potato>", "vec <<x> <y>>"), longestChains);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHelpQuery() {
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query1 = manager.getCommandHelpHandler().queryHelp("");
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query1 = manager.createCommandHelpHandler().queryHelp("");
|
||||
Assertions.assertTrue(query1 instanceof CommandHelpHandler.IndexHelpTopic);
|
||||
this.printTopic("", query1);
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query2 = manager.getCommandHelpHandler().queryHelp("test");
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query2 = manager.createCommandHelpHandler().queryHelp("test");
|
||||
Assertions.assertTrue(query2 instanceof CommandHelpHandler.MultiHelpTopic);
|
||||
this.printTopic("test", query2);
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query3 = manager.getCommandHelpHandler().queryHelp("test int");
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query3 = manager.createCommandHelpHandler().queryHelp("test int");
|
||||
Assertions.assertTrue(query3 instanceof CommandHelpHandler.VerboseHelpTopic);
|
||||
this.printTopic("test int", query3);
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query4 = manager.getCommandHelpHandler().queryHelp("vec");
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query4 = manager.createCommandHelpHandler().queryHelp("vec");
|
||||
Assertions.assertTrue(query4 instanceof CommandHelpHandler.VerboseHelpTopic);
|
||||
this.printTopic("vec", query4);
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ class CommandHelpHandlerTest {
|
|||
* - /test <potato>
|
||||
* - /test int <int>
|
||||
*/
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query1 = manager.getCommandHelpHandler(predicate).queryHelp("");
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query1 = manager.createCommandHelpHandler(predicate).queryHelp("");
|
||||
Assertions.assertTrue(query1 instanceof CommandHelpHandler.IndexHelpTopic);
|
||||
Assertions.assertEquals(Arrays.asList("test <potato>", "test int <int>"), getSortedSyntaxStrings(query1));
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ class CommandHelpHandlerTest {
|
|||
* - /test <potato>
|
||||
* - /test int <int>
|
||||
*/
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query2 = manager.getCommandHelpHandler(predicate).queryHelp("test");
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query2 = manager.createCommandHelpHandler(predicate).queryHelp("test");
|
||||
Assertions.assertTrue(query2 instanceof CommandHelpHandler.MultiHelpTopic);
|
||||
Assertions.assertEquals(Arrays.asList("test <potato>", "test int <int>"), getSortedSyntaxStrings(query2));
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ class CommandHelpHandlerTest {
|
|||
* List all commands from /test int, which should show only:
|
||||
* - /test int <int>
|
||||
*/
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query3 = manager.getCommandHelpHandler(predicate).queryHelp(
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query3 = manager.createCommandHelpHandler(predicate).queryHelp(
|
||||
"test int");
|
||||
Assertions.assertTrue(query3 instanceof CommandHelpHandler.VerboseHelpTopic);
|
||||
Assertions.assertEquals(Collections.singletonList("test int <int>"), getSortedSyntaxStrings(query3));
|
||||
|
|
@ -143,7 +143,7 @@ class CommandHelpHandlerTest {
|
|||
/*
|
||||
* List all commands from /vec, which should show none
|
||||
*/
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query4 = manager.getCommandHelpHandler(predicate).queryHelp("vec");
|
||||
final CommandHelpHandler.HelpTopic<TestCommandSender> query4 = manager.createCommandHelpHandler(predicate).queryHelp("vec");
|
||||
Assertions.assertTrue(query4 instanceof CommandHelpHandler.IndexHelpTopic);
|
||||
Assertions.assertEquals(Collections.emptyList(), getSortedSyntaxStrings(query4));
|
||||
}
|
||||
|
|
@ -239,7 +239,7 @@ class CommandHelpHandlerTest {
|
|||
}
|
||||
|
||||
private void printVerboseHelpTopic(final CommandHelpHandler.VerboseHelpTopic<TestCommandSender> helpTopic) {
|
||||
System.out.printf("└── Command: /%s\n", manager.getCommandSyntaxFormatter()
|
||||
System.out.printf("└── Command: /%s\n", manager.commandSyntaxFormatter()
|
||||
.apply(helpTopic.getCommand().getArguments(), null));
|
||||
System.out.printf(" ├── Description: %s\n", helpTopic.getDescription());
|
||||
System.out.println(" └── Args: ");
|
||||
|
|
@ -252,7 +252,7 @@ class CommandHelpHandlerTest {
|
|||
description = ": " + description;
|
||||
}
|
||||
|
||||
System.out.printf(" %s %s%s\n", iterator.hasNext() ? "├──" : "└──", manager.getCommandSyntaxFormatter().apply(
|
||||
System.out.printf(" %s %s%s\n", iterator.hasNext() ? "├──" : "└──", manager.commandSyntaxFormatter().apply(
|
||||
Collections.singletonList(component.getArgument()), null), description);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ class CommandPermissionTest {
|
|||
@Override
|
||||
public boolean hasPermission(
|
||||
final @NonNull TestCommandSender sender,
|
||||
final String permission
|
||||
final @NonNull String permission
|
||||
) {
|
||||
if (permission.equalsIgnoreCase("first")) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class CommandRegistrationStateTest {
|
|||
@Test
|
||||
void testInitialState() {
|
||||
final CommandManager<TestCommandSender> manager = createManager();
|
||||
assertEquals(CommandManager.RegistrationState.BEFORE_REGISTRATION, manager.getRegistrationState());
|
||||
assertEquals(CommandManager.RegistrationState.BEFORE_REGISTRATION, manager.registrationState());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -45,7 +45,7 @@ public class CommandRegistrationStateTest {
|
|||
manager.command(manager.commandBuilder("test").handler(ctx -> {
|
||||
}));
|
||||
|
||||
assertEquals(CommandManager.RegistrationState.REGISTERING, manager.getRegistrationState());
|
||||
assertEquals(CommandManager.RegistrationState.REGISTERING, manager.registrationState());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -57,7 +57,7 @@ public class CommandRegistrationStateTest {
|
|||
manager.command(manager.commandBuilder("test2").handler(ctx -> {
|
||||
}));
|
||||
|
||||
assertEquals(CommandManager.RegistrationState.REGISTERING, manager.getRegistrationState());
|
||||
assertEquals(CommandManager.RegistrationState.REGISTERING, manager.registrationState());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -67,7 +67,7 @@ public class CommandRegistrationStateTest {
|
|||
}));
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> manager.setCommandRegistrationHandler(CommandRegistrationHandler.nullCommandRegistrationHandler())
|
||||
() -> manager.commandRegistrationHandler(CommandRegistrationHandler.nullCommandRegistrationHandler())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,19 +94,19 @@ class CommandTreeTest {
|
|||
);
|
||||
|
||||
// Act
|
||||
final Pair<Command<TestCommandSender>, Exception> command1 = this.commandManager.getCommandTree().parse(
|
||||
final Pair<Command<TestCommandSender>, Exception> command1 = this.commandManager.commandTree().parse(
|
||||
new CommandContext<>(new TestCommandSender(), this.commandManager),
|
||||
new LinkedList<>(Arrays.asList("test", "one"))
|
||||
);
|
||||
final Pair<Command<TestCommandSender>, Exception> command2 = this.commandManager.getCommandTree().parse(
|
||||
final Pair<Command<TestCommandSender>, Exception> command2 = this.commandManager.commandTree().parse(
|
||||
new CommandContext<>(new TestCommandSender(), this.commandManager),
|
||||
new LinkedList<>(Arrays.asList("test", "two"))
|
||||
);
|
||||
final Pair<Command<TestCommandSender>, Exception> command3 = this.commandManager.getCommandTree().parse(
|
||||
final Pair<Command<TestCommandSender>, Exception> command3 = this.commandManager.commandTree().parse(
|
||||
new CommandContext<>(new TestCommandSender(), this.commandManager),
|
||||
new LinkedList<>(Arrays.asList("test", "opt"))
|
||||
);
|
||||
final Pair<Command<TestCommandSender>, Exception> command4 = this.commandManager.getCommandTree().parse(
|
||||
final Pair<Command<TestCommandSender>, Exception> command4 = this.commandManager.commandTree().parse(
|
||||
new CommandContext<>(new TestCommandSender(), this.commandManager),
|
||||
new LinkedList<>(Arrays.asList("test", "opt", "12"))
|
||||
);
|
||||
|
|
@ -139,7 +139,7 @@ class CommandTreeTest {
|
|||
this.commandManager.command(command);
|
||||
|
||||
// Act
|
||||
final Command<TestCommandSender> result = this.commandManager.getCommandTree().parse(
|
||||
final Command<TestCommandSender> result = this.commandManager.commandTree().parse(
|
||||
new CommandContext<>(new TestCommandSender(), this.commandManager),
|
||||
new LinkedList<>(Arrays.asList("other", "öpt", "12"))
|
||||
).getFirst();
|
||||
|
|
@ -161,7 +161,7 @@ class CommandTreeTest {
|
|||
);
|
||||
|
||||
// Act
|
||||
final List<String> results = this.commandManager.getCommandTree().getSuggestions(
|
||||
final List<String> results = this.commandManager.commandTree().getSuggestions(
|
||||
new CommandContext<>(new TestCommandSender(), this.commandManager),
|
||||
new LinkedList<>(Arrays.asList("test", ""))
|
||||
);
|
||||
|
|
@ -492,7 +492,7 @@ class CommandTreeTest {
|
|||
);
|
||||
|
||||
/* Try parsing as a variable, which should match the variable command */
|
||||
final Pair<Command<TestCommandSender>, Exception> variableResult = this.commandManager.getCommandTree().parse(
|
||||
final Pair<Command<TestCommandSender>, Exception> variableResult = this.commandManager.commandTree().parse(
|
||||
new CommandContext<>(new TestCommandSender(), this.commandManager),
|
||||
new LinkedList<>(Arrays.asList("literalwithvariable", "argthatdoesnotmatch"))
|
||||
);
|
||||
|
|
@ -503,7 +503,7 @@ class CommandTreeTest {
|
|||
;
|
||||
|
||||
/* Try parsing with the main name literal, which should match the literal command */
|
||||
final Pair<Command<TestCommandSender>, Exception> literalResult = this.commandManager.getCommandTree().parse(
|
||||
final Pair<Command<TestCommandSender>, Exception> literalResult = this.commandManager.commandTree().parse(
|
||||
new CommandContext<>(new TestCommandSender(), this.commandManager),
|
||||
new LinkedList<>(Arrays.asList("literalwithvariable", "literal"))
|
||||
);
|
||||
|
|
@ -514,7 +514,7 @@ class CommandTreeTest {
|
|||
;
|
||||
|
||||
/* Try parsing with the alias of the literal, which should match the literal command */
|
||||
final Pair<Command<TestCommandSender>, Exception> literalAliasResult = this.commandManager.getCommandTree().parse(
|
||||
final Pair<Command<TestCommandSender>, Exception> literalAliasResult = this.commandManager.commandTree().parse(
|
||||
new CommandContext<>(new TestCommandSender(), this.commandManager),
|
||||
new LinkedList<>(Arrays.asList("literalwithvariable", "literalalias"))
|
||||
);
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ class Issue281 {
|
|||
) {
|
||||
@Override
|
||||
public boolean hasPermission(
|
||||
@NonNull final TestCommandSender sender,
|
||||
@NonNull final String permission
|
||||
final @NonNull TestCommandSender sender,
|
||||
final @NonNull String permission
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue