Package org.bukkit.command
Interface CommandMap
- All Known Implementing Classes:
SimpleCommandMap
public interface CommandMap
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears all registered commands.boolean
dispatch
(@NotNull CommandSender sender, @NotNull String cmdLine) Looks for the requested command and executes it if found.getCommand
(@NotNull String name) Gets the command registered to the specified nameReturn a Map of known commandsboolean
Registers a command.boolean
Registers a command.void
Registers all the commands belonging to a certain plugin.tabComplete
(@NotNull CommandSender sender, @NotNull String cmdLine) Looks for the requested command and executes an appropriate tab-completer if found.tabComplete
(@NotNull CommandSender sender, @NotNull String cmdLine, @Nullable Location location) Looks for the requested command and executes an appropriate tab-completer if found.
-
Method Details
-
registerAll
Registers all the commands belonging to a certain plugin.Caller can use:-
- command.getName() to determine the label registered for this command
- command.getAliases() to determine the aliases which where registered
- Parameters:
fallbackPrefix
- a prefix which is prepended to each command with a ':' one or more times to make the command uniquecommands
- a list of commands to register
-
register
boolean register(@NotNull @NotNull String label, @NotNull @NotNull String fallbackPrefix, @NotNull @NotNull Command command) Registers a command. Returns true on success; false if name is already taken and fallback had to be used.Caller can use:-
- command.getName() to determine the label registered for this command
- command.getAliases() to determine the aliases which where registered
- Parameters:
label
- the label of the command, without the '/'-prefix.fallbackPrefix
- a prefix which is prepended to the command with a ':' one or more times to make the command uniquecommand
- the command to register- Returns:
- true if command was registered with the passed in label, false otherwise, which indicates the fallbackPrefix was used one or more times
-
register
Registers a command. Returns true on success; false if name is already taken and fallback had to be used.Caller can use:-
- command.getName() to determine the label registered for this command
- command.getAliases() to determine the aliases which where registered
- Parameters:
fallbackPrefix
- a prefix which is prepended to the command with a ':' one or more times to make the command uniquecommand
- the command to register, from which label is determined from the command name- Returns:
- true if command was registered with the passed in label, false otherwise, which indicates the fallbackPrefix was used one or more times
-
dispatch
boolean dispatch(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String cmdLine) throws CommandException Looks for the requested command and executes it if found.- Parameters:
sender
- The command's sendercmdLine
- command + arguments. Example: "/test abc 123"- Returns:
- returns false if no target is found, true otherwise.
- Throws:
CommandException
- Thrown when the executor for the given command fails with an unhandled exception
-
clearCommands
void clearCommands()Clears all registered commands. -
getCommand
Gets the command registered to the specified name- Parameters:
name
- Name of the command to retrieve- Returns:
- Command with the specified name or null if a command with that label doesn't exist
-
tabComplete
@Nullable @Nullable List<String> tabComplete(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String cmdLine) throws IllegalArgumentException Looks for the requested command and executes an appropriate tab-completer if found. This method will also tab-complete partial commands.- Parameters:
sender
- The command's sender.cmdLine
- The entire command string to tab-complete, excluding initial slash.- Returns:
- a list of possible tab-completions. This list may be immutable. Will be null if no matching command of which sender has permission.
- Throws:
CommandException
- Thrown when the tab-completer for the given command fails with an unhandled exceptionIllegalArgumentException
- if either sender or cmdLine are null
-
tabComplete
@Nullable @Nullable List<String> tabComplete(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String cmdLine, @Nullable @Nullable Location location) throws IllegalArgumentException Looks for the requested command and executes an appropriate tab-completer if found. This method will also tab-complete partial commands.- Parameters:
sender
- The command's sender.cmdLine
- The entire command string to tab-complete, excluding initial slash.location
- The position looked at by the sender, or null if none- Returns:
- a list of possible tab-completions. This list may be immutable. Will be null if no matching command of which sender has permission.
- Throws:
CommandException
- Thrown when the tab-completer for the given command fails with an unhandled exceptionIllegalArgumentException
- if either sender or cmdLine are null
-
getKnownCommands
Return a Map of known commands- Returns:
- known commands
-