Package net.citizensnpcs.api.command
Class CommandManager
java.lang.Object
net.citizensnpcs.api.command.CommandManager
- All Implemented Interfaces:
TabCompleter
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
execute
(Command command, String[] args, CommandSender sender, Object... methodArgs) Attempt to execute a command using the rootCommand
given.boolean
executeSafe
(Command command, String[] args, CommandSender sender, Object... methodArgs) A safe version ofexecute(org.bukkit.command.Command, String[], CommandSender, Object...)
which catches and logs allException
s that occur.getClosestCommandModifier
(String command, String modifier) Searches for the closest modifier using Levenshtein distance to the given top level command and modifier.getCommand
(String... commandParts) Gets theCommandManager.CommandInfo
for the given command parts, ornull
if not found.getCommands
(String topLevelCommand) Gets all modified and root commands from the given root level command.boolean
hasCommand
(String... parts) Checks to see whether there is a command handler for the given command parts at the root level.boolean
hasCommand
(Command cmd, String... modifier) Checks to see whether there is a command handler for the given command at the root level.onTabComplete
(CommandSender sender, Command command, String alias, String[] args) void
Register a class that contains commands (methods annotated withCommand
).void
Registers anCommandAnnotationProcessor
that can process annotations before a command is executed.void
registerTabCompletion
(JavaPlugin plugin) void
void
setInjector
(Injector injector) void
setTranslationPrefixProvider
(Function<Command, String> provider)
-
Constructor Details
-
CommandManager
public CommandManager()
-
-
Method Details
-
execute
public void execute(Command command, String[] args, CommandSender sender, Object... methodArgs) throws CommandException Attempt to execute a command using the rootCommand
given. A list of method arguments may be used when calling the command handler method. A command handler method should follow the formcommand(CommandContext args, CommandSender sender)
whereCommandSender
can be replaced withPlayer
to only accept players. The method parameters must include the method args given, if any.- Parameters:
command
- The command to executeargs
- The arguments of the commandsender
- The sender of the commandmethodArgs
- The method arguments to be used when calling the command handler- Throws:
CommandException
- Any exceptions caused from execution of the command
-
executeSafe
public boolean executeSafe(Command command, String[] args, CommandSender sender, Object... methodArgs) A safe version ofexecute(org.bukkit.command.Command, String[], CommandSender, Object...)
which catches and logs allException
s that occur.- Returns:
- Whether command usage should be printed
- See Also:
-
getClosestCommandModifier
Searches for the closest modifier using Levenshtein distance to the given top level command and modifier.- Parameters:
command
- The top level commandmodifier
- The modifier to use as the base- Returns:
- The closest modifier, or empty
-
getCommand
Gets theCommandManager.CommandInfo
for the given command parts, ornull
if not found.- Parameters:
commandParts
- The parts of the command- Returns:
- The command info for the command
-
getCommands
Gets all modified and root commands from the given root level command. For example, if /npc look and /npc jump were defined, callinggetCommands("npc")
would returnCommandManager.CommandInfo
s for both commands.- Parameters:
topLevelCommand
- The root level command- Returns:
- The list of
CommandManager.CommandInfo
s
-
hasCommand
Checks to see whether there is a command handler for the given command at the root level. This will check aliases as well.- Parameters:
cmd
- The command to checkmodifier
- The modifier to check (may be empty)- Returns:
- Whether the command is handled
-
hasCommand
Checks to see whether there is a command handler for the given command parts at the root level. This will check aliases as well.- Parameters:
parts
- The parts to check (must not be empty)- Returns:
- Whether the command is handled
-
onTabComplete
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) - Specified by:
onTabComplete
in interfaceTabCompleter
-
register
Register a class that contains commands (methods annotated withCommand
). If no dependencyInjector
is specified, then only static methods of the class will be registered. Otherwise, new instances the command class will be created and instance methods will be called.- Parameters:
clazz
- The class to scan- See Also:
-
registerAnnotationProcessor
Registers anCommandAnnotationProcessor
that can process annotations before a command is executed. Methods with theCommand
annotation will have the rest of their annotations scanned and stored if there is a matchingCommandAnnotationProcessor
. Annotations that do not have a processor are discarded. The scanning method uses annotations from the declaring class as a base before narrowing using the method's annotations.- Parameters:
processor
- The annotation processor
-
registerTabCompletion
-
setDefaultDurationUnits
-
setInjector
-
setTranslationPrefixProvider
-