feat: allow a custom CaptionVariableReplacementHandler (#352)
This commit is contained in:
parent
7b23dd0329
commit
2277bf5ef8
3 changed files with 30 additions and 3 deletions
|
|
@ -35,7 +35,9 @@ import cloud.commandframework.arguments.parser.ParserParameter;
|
|||
import cloud.commandframework.arguments.parser.ParserRegistry;
|
||||
import cloud.commandframework.arguments.parser.StandardParserRegistry;
|
||||
import cloud.commandframework.captions.CaptionRegistry;
|
||||
import cloud.commandframework.captions.CaptionVariableReplacementHandler;
|
||||
import cloud.commandframework.captions.SimpleCaptionRegistryFactory;
|
||||
import cloud.commandframework.captions.SimpleCaptionVariableReplacementHandler;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.context.CommandContextFactory;
|
||||
import cloud.commandframework.context.StandardCommandContextFactory;
|
||||
|
|
@ -96,6 +98,7 @@ public abstract class CommandManager<C> {
|
|||
private final CommandTree<C> commandTree;
|
||||
private final CommandSuggestionEngine<C> commandSuggestionEngine;
|
||||
|
||||
private CaptionVariableReplacementHandler captionVariableReplacementHandler = new SimpleCaptionVariableReplacementHandler();
|
||||
private CommandSyntaxFormatter<C> commandSyntaxFormatter = new StandardCommandSyntaxFormatter<>();
|
||||
private CommandSuggestionProcessor<C> commandSuggestionProcessor = new FilteringCommandSuggestionProcessor<>();
|
||||
private CommandRegistrationHandler commandRegistrationHandler;
|
||||
|
|
@ -240,6 +243,28 @@ public abstract class CommandManager<C> {
|
|||
return this.command(command.manager(this).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the caption variable replacement handler.
|
||||
*
|
||||
* @return the caption variable replacement handler
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public @NonNull CaptionVariableReplacementHandler captionVariableReplacementHandler() {
|
||||
return this.captionVariableReplacementHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the caption variable replacement handler.
|
||||
*
|
||||
* @param captionVariableReplacementHandler new replacement handler
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public void captionVariableReplacementHandler(
|
||||
final @NonNull CaptionVariableReplacementHandler captionVariableReplacementHandler
|
||||
) {
|
||||
this.captionVariableReplacementHandler = captionVariableReplacementHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command syntax formatter
|
||||
*
|
||||
|
|
@ -455,7 +480,7 @@ public abstract class CommandManager<C> {
|
|||
* @param aliases Command aliases
|
||||
* @return Builder instance
|
||||
* @deprecated for removal since 1.4.0. Use {@link #commandBuilder(String, CommandMeta, ArgumentDescription, String...)}
|
||||
* instead.
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Command.@NonNull Builder<C> commandBuilder(
|
||||
|
|
|
|||
|
|
@ -52,8 +52,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||
*/
|
||||
public final class CommandContext<C> {
|
||||
|
||||
private final CaptionVariableReplacementHandler captionVariableReplacementHandler =
|
||||
new SimpleCaptionVariableReplacementHandler();
|
||||
private final CaptionVariableReplacementHandler captionVariableReplacementHandler;
|
||||
private final Map<CommandArgument<C, ?>, ArgumentTiming> argumentTimings = new HashMap<>();
|
||||
private final FlagContext flagContext = FlagContext.create();
|
||||
private final Map<CloudKey<?>, Object> internalStorage = new HashMap<>();
|
||||
|
|
@ -104,6 +103,7 @@ public final class CommandContext<C> {
|
|||
this.commandSender = commandSender;
|
||||
this.suggestions = suggestions;
|
||||
this.captionRegistry = captionRegistry;
|
||||
this.captionVariableReplacementHandler = new SimpleCaptionVariableReplacementHandler();
|
||||
this.commandManager = null;
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +124,7 @@ public final class CommandContext<C> {
|
|||
this.suggestions = suggestions;
|
||||
this.commandManager = commandManager;
|
||||
this.captionRegistry = commandManager.getCaptionRegistry();
|
||||
this.captionVariableReplacementHandler = commandManager.captionVariableReplacementHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue