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
Modifier and TypeFieldDescriptionprotected final CommandConditions<I,
CEC, CC> protected ExceptionHandler
protected MF
protected int
protected Map<MessageType,
MF> protected CommandHelpFormatter
protected List<IssuerLocaleChangedCallback<I>>
protected final CommandReplacements
protected Map<String,
RootCommand> protected boolean
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addSupportedLanguage
(Locale locale) Adds a new locale to the list of automatic Locales to load Message Bundles for.abstract CommandExecutionContext
createCommandContext
(RegisteredCommand command, CommandParameter parameter, CommandIssuer sender, List<String> args, int i, Map<String, Object> passedArgs) abstract CommandCompletionContext
createCompletionContext
(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 RootCommand
createRootCommand
(String cmd) void
enableUnstableAPI
(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 I
getCommandIssuer
(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 CommandIssuer
static CommandManager
static CommandOperationContext
Gets the current default exception handler, might be null.int
Deprecated.Unstable APIgetFormat
(MessageType type) Deprecated.Unstable APIgetIssuerLocale
(CommandIssuer issuer) abstract Locales
Returns 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 boolean
handleUncaughtException
(BaseCommand scope, RegisteredCommand registeredCommand, CommandIssuer sender, List<String> args, Throwable t) boolean
hasPermission
(CommandIssuer issuer, String permission) boolean
hasPermission
(CommandIssuer issuer, Set<String> permissions) abstract boolean
abstract boolean
isCommandIssuer
(Class<?> type) boolean
boolean
isValidName
(@NotNull String name) void
abstract void
void
notifyLocaleChange
(I issuer, Locale oldLocale, Locale newLocale) obtainRootCommand
(@NotNull String cmd) void
onLocaleChange
(IssuerLocaleChangedCallback<I> onChange) abstract void
registerCommand
(BaseCommand command) Registers a command with ACF<T> void
registerDependency
(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 withDependency
with the provided instance.<T> void
registerDependency
(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 withDependency
with the provided instance.void
sendMessage
(CommandIssuer issuer, MessageType type, co.aikar.locales.MessageKeyProvider key, String... replacements) void
sendMessage
(IT issuerArg, MessageType type, co.aikar.locales.MessageKeyProvider key, String... replacements) void
setDefaultExceptionHandler
(ExceptionHandler exceptionHandler) Sets the defaultExceptionHandler
that is called when an exception occurs while executing a command, if the command doesn't have its own exception handler registered.void
setDefaultExceptionHandler
(ExceptionHandler exceptionHandler, boolean logExceptions) Sets the defaultExceptionHandler
that 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.void
setDefaultFormatter
(MF defaultFormatter) void
setDefaultHelpPerPage
(int defaultHelpPerPage) Deprecated.Unstable APIvoid
setFormat
(MessageType type, int i, FT color) void
setFormat
(MessageType type, FT... colors) setFormat
(MessageType type, MF formatter) void
setHelpFormatter
(CommandHelpFormatter helpFormatter) Deprecated.Unstable APIsetIssuerLocale
(IT issuer, Locale locale) void
setValidNamePredicate
(@NotNull Predicate<String> isValidName) <T> void
unregisterDependency
(Class<? extends T> clazz) Unregisters an instance of the class, it will no longer be able to be injected<T> void
unregisterDependency
(Class<? extends T> clazz, String key) Unregisters an instance of the class, it will no longer be able to be injectedboolean
usePerIssuerLocale
(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 defaultExceptionHandler
that 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 defaultExceptionHandler
that 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 withDependency
with 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 withDependency
with 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
-