feat: allow a custom CaptionVariableReplacementHandler (#352)

This commit is contained in:
Aldin 2022-05-26 11:18:45 +02:00 committed by Jason
parent 7b23dd0329
commit 2277bf5ef8
3 changed files with 30 additions and 3 deletions

View file

@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added ### Added
- Allow for setting a custom `CaptionVariableReplacementHandler` on the command manager ([#352](https://github.com/Incendo/cloud/pull/352))
- Annotations: Annotation string processors ([#353](https://github.com/Incendo/cloud/pull/353)) - Annotations: Annotation string processors ([#353](https://github.com/Incendo/cloud/pull/353))
### Fixed ### Fixed

View file

@ -35,7 +35,9 @@ import cloud.commandframework.arguments.parser.ParserParameter;
import cloud.commandframework.arguments.parser.ParserRegistry; import cloud.commandframework.arguments.parser.ParserRegistry;
import cloud.commandframework.arguments.parser.StandardParserRegistry; import cloud.commandframework.arguments.parser.StandardParserRegistry;
import cloud.commandframework.captions.CaptionRegistry; import cloud.commandframework.captions.CaptionRegistry;
import cloud.commandframework.captions.CaptionVariableReplacementHandler;
import cloud.commandframework.captions.SimpleCaptionRegistryFactory; import cloud.commandframework.captions.SimpleCaptionRegistryFactory;
import cloud.commandframework.captions.SimpleCaptionVariableReplacementHandler;
import cloud.commandframework.context.CommandContext; import cloud.commandframework.context.CommandContext;
import cloud.commandframework.context.CommandContextFactory; import cloud.commandframework.context.CommandContextFactory;
import cloud.commandframework.context.StandardCommandContextFactory; import cloud.commandframework.context.StandardCommandContextFactory;
@ -96,6 +98,7 @@ public abstract class CommandManager<C> {
private final CommandTree<C> commandTree; private final CommandTree<C> commandTree;
private final CommandSuggestionEngine<C> commandSuggestionEngine; private final CommandSuggestionEngine<C> commandSuggestionEngine;
private CaptionVariableReplacementHandler captionVariableReplacementHandler = new SimpleCaptionVariableReplacementHandler();
private CommandSyntaxFormatter<C> commandSyntaxFormatter = new StandardCommandSyntaxFormatter<>(); private CommandSyntaxFormatter<C> commandSyntaxFormatter = new StandardCommandSyntaxFormatter<>();
private CommandSuggestionProcessor<C> commandSuggestionProcessor = new FilteringCommandSuggestionProcessor<>(); private CommandSuggestionProcessor<C> commandSuggestionProcessor = new FilteringCommandSuggestionProcessor<>();
private CommandRegistrationHandler commandRegistrationHandler; private CommandRegistrationHandler commandRegistrationHandler;
@ -240,6 +243,28 @@ public abstract class CommandManager<C> {
return this.command(command.manager(this).build()); 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 * Get the command syntax formatter
* *

View file

@ -52,8 +52,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/ */
public final class CommandContext<C> { public final class CommandContext<C> {
private final CaptionVariableReplacementHandler captionVariableReplacementHandler = private final CaptionVariableReplacementHandler captionVariableReplacementHandler;
new SimpleCaptionVariableReplacementHandler();
private final Map<CommandArgument<C, ?>, ArgumentTiming> argumentTimings = new HashMap<>(); private final Map<CommandArgument<C, ?>, ArgumentTiming> argumentTimings = new HashMap<>();
private final FlagContext flagContext = FlagContext.create(); private final FlagContext flagContext = FlagContext.create();
private final Map<CloudKey<?>, Object> internalStorage = new HashMap<>(); private final Map<CloudKey<?>, Object> internalStorage = new HashMap<>();
@ -104,6 +103,7 @@ public final class CommandContext<C> {
this.commandSender = commandSender; this.commandSender = commandSender;
this.suggestions = suggestions; this.suggestions = suggestions;
this.captionRegistry = captionRegistry; this.captionRegistry = captionRegistry;
this.captionVariableReplacementHandler = new SimpleCaptionVariableReplacementHandler();
this.commandManager = null; this.commandManager = null;
} }
@ -124,6 +124,7 @@ public final class CommandContext<C> {
this.suggestions = suggestions; this.suggestions = suggestions;
this.commandManager = commandManager; this.commandManager = commandManager;
this.captionRegistry = commandManager.getCaptionRegistry(); this.captionRegistry = commandManager.getCaptionRegistry();
this.captionVariableReplacementHandler = commandManager.captionVariableReplacementHandler();
} }
/** /**