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
Fields Modifier and Type Field Description protected CommandConditions<I,CEC,CC>conditionsprotected ExceptionHandlerdefaultExceptionHandlerprotected MFdefaultFormatterprotected intdefaultHelpPerPageprotected Table<Class<?>,String,Object>dependenciesprotected Map<MessageType,MF>formattersprotected CommandHelpFormatterhelpFormatterprotected Map<UUID,Locale>issuersLocaleprotected List<IssuerLocaleChangedCallback<I>>localeChangedCallbacksprotected CommandReplacementsreplacementsprotected Map<String,RootCommand>rootCommandsprotected Set<Locale>supportedLanguagesprotected booleanusePerIssuerLocale
-
Constructor Summary
Constructors Constructor Description CommandManager()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddSupportedLanguage(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)ConditionContextcreateConditionContext(CommandIssuer issuer, String config)RegisteredCommandcreateRegisteredCommand(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'sStringformatMessage(CommandIssuer issuer, MessageType type, co.aikar.locales.MessageKeyProvider key, String... replacements)CommandHelpgenerateCommandHelp()Deprecated.Unstable APICommandHelpgenerateCommandHelp(@NotNull String command)Deprecated.Unstable APICommandHelpgenerateCommandHelp(CommandIssuer issuer, @NotNull String command)Deprecated.Unstable APICommandHelpgenerateCommandHelp(CommandIssuer issuer, RootCommand rootCommand)Deprecated.Unstable APIabstract CommandCompletions<?>getCommandCompletions()Gets the command completions managerCommandConditions<I,CEC,CC>getCommandConditions()abstract CommandContexts<?>getCommandContexts()Gets the command contexts managerabstract IgetCommandIssuer(Object issuer)StringgetCommandPrefix(CommandIssuer issuer)CommandReplacementsgetCommandReplacements()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 CommandIssuergetCurrentCommandIssuer()static CommandManagergetCurrentCommandManager()static CommandOperationContextgetCurrentCommandOperationContext()ExceptionHandlergetDefaultExceptionHandler()Gets the current default exception handler, might be null.MFgetDefaultFormatter()intgetDefaultHelpPerPage()Deprecated.Unstable APIMFgetFormat(MessageType type)CommandHelpFormattergetHelpFormatter()Deprecated.Unstable APILocalegetIssuerLocale(CommandIssuer issuer)abstract LocalesgetLocales()Returns a Locales Manager to add and modify language tables for your commands.abstract Collection<RootCommand>getRegisteredRootCommands()RootCommandgetRootCommand(@NotNull String cmd)Set<Locale>getSupportedLanguages()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 booleanhasRegisteredCommands()abstract booleanisCommandIssuer(Class<?> type)booleanisLoggingUnhandledExceptions()voidlog(co.aikar.commands.LogLevel level, String message)abstract voidlog(co.aikar.commands.LogLevel level, String message, Throwable throwable)voidnotifyLocaleChange(I issuer, Locale oldLocale, Locale newLocale)RootCommandobtainRootCommand(@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 it's 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 it's 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)MFsetFormat(MessageType type, MF formatter)voidsetHelpFormatter(CommandHelpFormatter helpFormatter)Deprecated.Unstable APILocalesetIssuerLocale(IT issuer, Locale locale)booleanusePerIssuerLocale(boolean setting)booleanusingPerIssuerLocale()
-
-
-
Field Detail
-
rootCommands
protected Map<String,RootCommand> rootCommands
-
replacements
protected final CommandReplacements replacements
-
conditions
protected final CommandConditions<I extends CommandIssuer,CEC extends CommandExecutionContext<CEC,I>,CC extends ConditionContext<I>> conditions
-
defaultExceptionHandler
protected ExceptionHandler defaultExceptionHandler
-
dependencies
protected Table<Class<?>,String,Object> dependencies
-
helpFormatter
protected CommandHelpFormatter helpFormatter
-
usePerIssuerLocale
protected boolean usePerIssuerLocale
-
localeChangedCallbacks
protected List<IssuerLocaleChangedCallback<I extends CommandIssuer>> localeChangedCallbacks
-
supportedLanguages
protected Set<Locale> supportedLanguages
-
formatters
protected Map<MessageType,MF extends MessageFormatter<FT>> formatters
-
defaultFormatter
protected MF extends MessageFormatter<FT> defaultFormatter
-
defaultHelpPerPage
protected int defaultHelpPerPage
-
issuersLocale
protected Map<UUID,Locale> issuersLocale
-
-
Constructor Detail
-
CommandManager
public CommandManager()
-
-
Method Detail
-
getCurrentCommandOperationContext
public static CommandOperationContext getCurrentCommandOperationContext()
-
getCurrentCommandIssuer
public static CommandIssuer getCurrentCommandIssuer()
-
getCurrentCommandManager
public static CommandManager getCurrentCommandManager()
-
setFormat
public MF setFormat(MessageType type, MF formatter)
-
getFormat
public MF getFormat(MessageType type)
-
setFormat
public void setFormat(MessageType type, FT... colors)
-
setFormat
public void setFormat(MessageType type, int i, FT color)
-
getDefaultFormatter
public MF getDefaultFormatter()
-
setDefaultFormatter
public void setDefaultFormatter(MF defaultFormatter)
-
getCommandConditions
public CommandConditions<I,CEC,CC> getCommandConditions()
-
getCommandContexts
public abstract CommandContexts<?> getCommandContexts()
Gets the command contexts manager- Returns:
- Command Contexts
-
getCommandCompletions
public abstract CommandCompletions<?> getCommandCompletions()
Gets the command completions manager- Returns:
- Command Completions
-
generateCommandHelp
@Deprecated public CommandHelp generateCommandHelp(@NotNull @NotNull String command)
Deprecated.Unstable API
-
generateCommandHelp
@Deprecated public CommandHelp generateCommandHelp(CommandIssuer issuer, @NotNull @NotNull String command)
Deprecated.Unstable API
-
generateCommandHelp
@Deprecated public CommandHelp generateCommandHelp()
Deprecated.Unstable API
-
generateCommandHelp
@Deprecated public CommandHelp generateCommandHelp(CommandIssuer issuer, RootCommand rootCommand)
Deprecated.Unstable API
-
getDefaultHelpPerPage
@Deprecated public int getDefaultHelpPerPage()
Deprecated.Unstable API
-
setDefaultHelpPerPage
@Deprecated public void setDefaultHelpPerPage(int defaultHelpPerPage)
Deprecated.Unstable API
-
setHelpFormatter
@Deprecated public void setHelpFormatter(CommandHelpFormatter helpFormatter)
Deprecated.Unstable API
-
getHelpFormatter
@Deprecated public CommandHelpFormatter getHelpFormatter()
Deprecated.Unstable API
-
registerCommand
public abstract void registerCommand(BaseCommand command)
Registers a command with ACF- Parameters:
command- The command to register
-
hasRegisteredCommands
public abstract boolean hasRegisteredCommands()
-
isCommandIssuer
public abstract boolean isCommandIssuer(Class<?> type)
-
getCommandIssuer
public abstract I getCommandIssuer(Object issuer)
-
createRootCommand
public abstract RootCommand createRootCommand(String cmd)
-
getLocales
public abstract Locales getLocales()
Returns a Locales Manager to add and modify language tables for your commands.- Returns:
-
usingPerIssuerLocale
public boolean usingPerIssuerLocale()
-
usePerIssuerLocale
public boolean usePerIssuerLocale(boolean setting)
-
createConditionContext
public ConditionContext createConditionContext(CommandIssuer issuer, String config)
-
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
public abstract void log(co.aikar.commands.LogLevel level, String message, Throwable throwable)
-
getCommandReplacements
public CommandReplacements 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
public boolean hasPermission(CommandIssuer issuer, Set<String> permissions)
-
hasPermission
public boolean hasPermission(CommandIssuer issuer, String permission)
-
getRootCommand
public RootCommand getRootCommand(@NotNull @NotNull String cmd)
-
obtainRootCommand
public RootCommand obtainRootCommand(@NotNull @NotNull String cmd)
-
getRegisteredRootCommands
public abstract Collection<RootCommand> getRegisteredRootCommands()
-
createRegisteredCommand
public RegisteredCommand createRegisteredCommand(BaseCommand command, String cmdName, Method method, String prefSubCommand)
-
setDefaultExceptionHandler
public void setDefaultExceptionHandler(ExceptionHandler exceptionHandler)
Sets the defaultExceptionHandlerthat is called when an exception occurs while executing a command, if the command doesn't have it's own exception handler registered.- Parameters:
exceptionHandler- the handler that should handle uncaught exceptions. May not be null if logExceptions is false
-
setDefaultExceptionHandler
public void setDefaultExceptionHandler(ExceptionHandler exceptionHandler, boolean logExceptions)
Sets the defaultExceptionHandlerthat is called when an exception occurs while executing a command, if the command doesn't have it's 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
public boolean isLoggingUnhandledExceptions()
-
getDefaultExceptionHandler
public ExceptionHandler 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
public void onLocaleChange(IssuerLocaleChangedCallback<I> onChange)
-
notifyLocaleChange
public void notifyLocaleChange(I issuer, Locale oldLocale, Locale newLocale)
-
setIssuerLocale
public Locale setIssuerLocale(IT issuer, Locale locale)
-
getIssuerLocale
public Locale getIssuerLocale(CommandIssuer issuer)
-
getSupportedLanguages
public Set<Locale> getSupportedLanguages()
Gets a list of all currently supported languages for this manager. These locales will be automatically loaded from- Returns:
-
addSupportedLanguage
public void addSupportedLanguage(Locale locale)
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
public <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 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
public <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 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
-
enableUnstableAPI
@Deprecated public 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's
-
getCommandPrefix
public String getCommandPrefix(CommandIssuer issuer)
-
-