Package net.citizensnpcs.api.command
Class CommandManager
java.lang.Object
net.citizensnpcs.api.command.CommandManager
- All Implemented Interfaces:
TabCompleter
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(Command command, String[] args, CommandSender sender, Object... methodArgs) Attempt to execute a command using the rootCommandgiven.booleanexecuteSafe(Command command, String[] args, CommandSender sender, Object... methodArgs) A safe version ofexecute(org.bukkit.command.Command, String[], CommandSender, Object...)which catches and logs allExceptions 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.CommandInfofor the given command parts, ornullif not found.getCommands(String topLevelCommand) Gets all modified and root commands from the given root level command.booleanhasCommand(String... parts) Checks to see whether there is a command handler for the given command parts at the root level.booleanhasCommand(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) voidRegister a class that contains commands (methods annotated withCommand).voidRegisters anCommandAnnotationProcessorthat can process annotations before a command is executed.voidregisterTabCompletion(JavaPlugin plugin) voidvoidsetInjector(Injector injector) voidsetTranslationPrefixProvider(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 rootCommandgiven. 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)whereCommandSendercan be replaced withPlayerto 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 allExceptions 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.CommandInfofor the given command parts, ornullif 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.CommandInfos for both commands.- Parameters:
topLevelCommand- The root level command- Returns:
- The list of
CommandManager.CommandInfos
-
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:
onTabCompletein interfaceTabCompleter
-
register
Register a class that contains commands (methods annotated withCommand). If no dependencyInjectoris 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 anCommandAnnotationProcessorthat can process annotations before a command is executed. Methods with theCommandannotation 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
-