Package co.aikar.commands
Class CommandManager<IT,I extends CommandIssuer,FT,MF extends MessageFormatter<FT>,CEC extends CommandExecutionContext<CEC,I>,CC extends ConditionContext<I>>
java.lang.Object
co.aikar.commands.CommandManager<IT,I,FT,MF,CEC,CC>
public abstract class CommandManager<IT,I extends CommandIssuer,FT,MF extends MessageFormatter<FT>,CEC extends CommandExecutionContext<CEC,I>,CC extends ConditionContext<I>>
extends Object
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CommandConditions<I,CEC, CC> protected ExceptionHandlerprotected MFprotected intprotected Map<MessageType,MF> protected CommandHelpFormatterprotected List<IssuerLocaleChangedCallback<I>>protected final CommandReplacementsprotected Map<String,RootCommand> protected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSupportedLanguage(Locale locale) Adds a new locale to the list of automatic Locales to load Message Bundles for.abstract CommandExecutionContextcreateCommandContext(RegisteredCommand command, CommandParameter parameter, CommandIssuer sender, List<String> args, int i, Map<String, Object> passedArgs) abstract CommandCompletionContextcreateCompletionContext(RegisteredCommand command, CommandIssuer sender, String input, String config, String[] args) createConditionContext(CommandIssuer issuer, String config) createRegisteredCommand(BaseCommand command, String cmdName, Method method, String prefSubCommand) abstract RootCommandcreateRootCommand(String cmd) voidenableUnstableAPI(String api) Deprecated.Use this with caution! If you enable and use Unstable API's, your next compile using ACF may require you to update your implementation to those unstable API'sformatMessage(CommandIssuer issuer, MessageType type, co.aikar.locales.MessageKeyProvider key, String... replacements) Deprecated.Unstable APIgenerateCommandHelp(@NotNull String command) Deprecated.Unstable APIgenerateCommandHelp(CommandIssuer issuer, @NotNull String command) Deprecated.Unstable APIgenerateCommandHelp(CommandIssuer issuer, RootCommand rootCommand) Deprecated.Unstable APIabstract CommandCompletions<?>Gets the command completions managerabstract CommandContexts<?>Gets the command contexts managerabstract IgetCommandIssuer(Object issuer) getCommandPrefix(CommandIssuer issuer) Lets you add custom string replacements that can be applied to annotation values, to reduce duplication/repetition of common values such as permission nodes and command prefixes.static CommandIssuerstatic CommandManagerstatic CommandOperationContextGets the current default exception handler, might be null.intDeprecated.Unstable APIgetFormat(MessageType type) Deprecated.Unstable APIgetIssuerLocale(CommandIssuer issuer) abstract LocalesReturns a Locales Manager to add and modify language tables for your commands.abstract Collection<RootCommand>getRootCommand(@NotNull String cmd) Gets a list of all currently supported languages for this manager.protected booleanhandleUncaughtException(BaseCommand scope, RegisteredCommand registeredCommand, CommandIssuer sender, List<String> args, Throwable t) booleanhasPermission(CommandIssuer issuer, String permission) booleanhasPermission(CommandIssuer issuer, Set<String> permissions) abstract booleanabstract booleanisCommandIssuer(Class<?> type) booleanbooleanisValidName(@NotNull String name) voidabstract voidvoidnotifyLocaleChange(I issuer, Locale oldLocale, Locale newLocale) obtainRootCommand(@NotNull String cmd) voidonLocaleChange(IssuerLocaleChangedCallback<I> onChange) abstract voidregisterCommand(BaseCommand command) Registers a command with ACF<T> voidregisterDependency(Class<? extends T> clazz, String key, T instance) Registers an instance of a class to be registered as an injectable dependency.
The command manager will attempt to inject all fields in a command class that are annotated withDependencywith the provided instance.<T> voidregisterDependency(Class<? extends T> clazz, T instance) Registers an instance of a class to be registered as an injectable dependency.
The command manager will attempt to inject all fields in a command class that are annotated withDependencywith the provided instance.voidsendMessage(CommandIssuer issuer, MessageType type, co.aikar.locales.MessageKeyProvider key, String... replacements) voidsendMessage(IT issuerArg, MessageType type, co.aikar.locales.MessageKeyProvider key, String... replacements) voidsetDefaultExceptionHandler(ExceptionHandler exceptionHandler) Sets the defaultExceptionHandlerthat is called when an exception occurs while executing a command, if the command doesn't have its own exception handler registered.voidsetDefaultExceptionHandler(ExceptionHandler exceptionHandler, boolean logExceptions) Sets the defaultExceptionHandlerthat is called when an exception occurs while executing a command, if the command doesn't have its own exception handler registered, and lets you control if ACF should also log the exception still.voidsetDefaultFormatter(MF defaultFormatter) voidsetDefaultHelpPerPage(int defaultHelpPerPage) Deprecated.Unstable APIvoidsetFormat(MessageType type, int i, FT color) voidsetFormat(MessageType type, FT... colors) setFormat(MessageType type, MF formatter) voidsetHelpFormatter(CommandHelpFormatter helpFormatter) Deprecated.Unstable APIsetIssuerLocale(IT issuer, Locale locale) voidsetValidNamePredicate(@NotNull Predicate<String> isValidName) <T> voidunregisterDependency(Class<? extends T> clazz) Unregisters an instance of the class, it will no longer be able to be injected<T> voidunregisterDependency(Class<? extends T> clazz, String key) Unregisters an instance of the class, it will no longer be able to be injectedbooleanusePerIssuerLocale(boolean setting) boolean
-
Field Details
-
rootCommands
-
replacements
-
conditions
protected final CommandConditions<I extends CommandIssuer,CEC extends CommandExecutionContext<CEC, conditionsI>, CC extends ConditionContext<I>> -
defaultExceptionHandler
-
dependencies
-
helpFormatter
-
usePerIssuerLocale
-
localeChangedCallbacks
-
supportedLanguages
-
validNamePredicate
-
formatters
-
defaultFormatter
-
defaultHelpPerPage
-
issuersLocale
-
-
Constructor Details
-
CommandManager
public CommandManager()
-
-
Method Details
-
getCurrentCommandOperationContext
-
getCurrentCommandIssuer
-
getCurrentCommandManager
-
setFormat
-
getFormat
-
setFormat
-
setFormat
-
getDefaultFormatter
-
setDefaultFormatter
-
getCommandConditions
-
getCommandContexts
Gets the command contexts manager- Returns:
- Command Contexts
-
getCommandCompletions
Gets the command completions manager- Returns:
- Command Completions
-
generateCommandHelp
Deprecated.Unstable API -
generateCommandHelp
@Deprecated public CommandHelp generateCommandHelp(CommandIssuer issuer, @NotNull @NotNull String command) Deprecated.Unstable API -
generateCommandHelp
Deprecated.Unstable API -
generateCommandHelp
Deprecated.Unstable API -
getDefaultHelpPerPage
Deprecated.Unstable API -
setDefaultHelpPerPage
Deprecated.Unstable API -
setHelpFormatter
Deprecated.Unstable API -
getHelpFormatter
Deprecated.Unstable API -
registerCommand
Registers a command with ACF- Parameters:
command- The command to register
-
hasRegisteredCommands
-
isCommandIssuer
-
getCommandIssuer
-
createRootCommand
-
getLocales
Returns a Locales Manager to add and modify language tables for your commands.- Returns:
-
usingPerIssuerLocale
-
usePerIssuerLocale
-
isValidName
-
getValidNamePredicate
-
setValidNamePredicate
-
createConditionContext
-
createCommandContext
public abstract CommandExecutionContext createCommandContext(RegisteredCommand command, CommandParameter parameter, CommandIssuer sender, List<String> args, int i, Map<String, Object> passedArgs) -
createCompletionContext
public abstract CommandCompletionContext createCompletionContext(RegisteredCommand command, CommandIssuer sender, String input, String config, String[] args) -
log
-
log
-
getCommandReplacements
Lets you add custom string replacements that can be applied to annotation values, to reduce duplication/repetition of common values such as permission nodes and command prefixes.Any replacement registered starts with a %
So for ex @CommandPermission("%staff")
- Returns:
- Replacements Manager
-
hasPermission
-
hasPermission
-
getRootCommand
-
obtainRootCommand
-
getRegisteredRootCommands
-
createRegisteredCommand
public RegisteredCommand createRegisteredCommand(BaseCommand command, String cmdName, Method method, String prefSubCommand) -
setDefaultExceptionHandler
Sets the defaultExceptionHandlerthat is called when an exception occurs while executing a command, if the command doesn't have its own exception handler registered.- Parameters:
exceptionHandler- the handler that should handle uncaught exceptions. May not be null if logExceptions is false
-
setDefaultExceptionHandler
Sets the defaultExceptionHandlerthat is called when an exception occurs while executing a command, if the command doesn't have its own exception handler registered, and lets you control if ACF should also log the exception still.If you disable logging, you need to log it yourself in your handler.
- Parameters:
exceptionHandler- the handler that should handle uncaught exceptions. May not be null if logExceptions is falselogExceptions- Whether or not to log exceptions.
-
isLoggingUnhandledExceptions
-
getDefaultExceptionHandler
Gets the current default exception handler, might be null.- Returns:
- the default exception handler
-
handleUncaughtException
protected boolean handleUncaughtException(BaseCommand scope, RegisteredCommand registeredCommand, CommandIssuer sender, List<String> args, Throwable t) -
sendMessage
public void sendMessage(IT issuerArg, MessageType type, co.aikar.locales.MessageKeyProvider key, String... replacements) -
sendMessage
public void sendMessage(CommandIssuer issuer, MessageType type, co.aikar.locales.MessageKeyProvider key, String... replacements) -
formatMessage
public String formatMessage(CommandIssuer issuer, MessageType type, co.aikar.locales.MessageKeyProvider key, String... replacements) -
onLocaleChange
-
notifyLocaleChange
-
setIssuerLocale
-
getIssuerLocale
-
getSupportedLanguages
Gets a list of all currently supported languages for this manager. These locales will be automatically loaded from- Returns:
-
addSupportedLanguage
Adds a new locale to the list of automatic Locales to load Message Bundles for. All bundles loaded under the previous supported languages will now automatically load for this new locale too.- Parameters:
locale-
-
registerDependency
Registers an instance of a class to be registered as an injectable dependency.
The command manager will attempt to inject all fields in a command class that are annotated withDependencywith the provided instance.- Parameters:
clazz- the class the injector should look for when injectinginstance- the instance of the class that should be injected- Throws:
IllegalStateException- when there is already an instance for the provided class registered
-
registerDependency
Registers an instance of a class to be registered as an injectable dependency.
The command manager will attempt to inject all fields in a command class that are annotated withDependencywith the provided instance.- Parameters:
clazz- the class the injector should look for when injectingkey- the key which needs to be present if thatinstance- the instance of the class that should be injected- Throws:
IllegalStateException- when there is already an instance for the provided class registered
-
unregisterDependency
Unregisters an instance of the class, it will no longer be able to be injected- Parameters:
clazz- the class the injector should look for to remove- Throws:
IllegalStateException- If the dependency was not found.
-
unregisterDependency
Unregisters an instance of the class, it will no longer be able to be injected- Parameters:
clazz- the class the injector should look for to removekey- the key which needs to be present if that- Throws:
IllegalStateException- If the dependency was not found.
-
enableUnstableAPI
Deprecated.Use this with caution! If you enable and use Unstable API's, your next compile using ACF may require you to update your implementation to those unstable API's -
getCommandPrefix
-