Package org.bukkit.command
Class SimpleCommandMap
- java.lang.Object
-
- org.bukkit.command.SimpleCommandMap
-
- All Implemented Interfaces:
CommandMap
public class SimpleCommandMap extends Object implements CommandMap
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,Command>
knownCommands
-
Constructor Summary
Constructors Constructor Description SimpleCommandMap(@NotNull Server server)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearCommands()
Clears all registered commands.boolean
dispatch(@NotNull CommandSender sender, @NotNull String commandLine)
Looks for the requested command and executes it if found.@Nullable Command
getCommand(@NotNull String name)
Gets the command registered to the specified name@NotNull Collection<Command>
getCommands()
boolean
register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command)
Registers a command.boolean
register(@NotNull String fallbackPrefix, @NotNull Command command)
Registers a command.void
registerAll(@NotNull String fallbackPrefix, @NotNull List<Command> commands)
Registers all the commands belonging to a certain plugin.void
registerServerAliases()
void
setFallbackCommands()
@Nullable List<String>
tabComplete(@NotNull CommandSender sender, @NotNull String cmdLine)
Looks for the requested command and executes an appropriate tab-completer if found.@Nullable List<String>
tabComplete(@NotNull CommandSender sender, @NotNull String cmdLine, @Nullable Location location)
Looks for the requested command and executes an appropriate tab-completer if found.
-
-
-
Constructor Detail
-
SimpleCommandMap
public SimpleCommandMap(@NotNull @NotNull Server server)
-
-
Method Detail
-
setFallbackCommands
public void setFallbackCommands()
-
registerAll
public void registerAll(@NotNull @NotNull String fallbackPrefix, @NotNull @NotNull List<Command> commands)
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
- Specified by:
registerAll
in interfaceCommandMap
- 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
public boolean register(@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
- Specified by:
register
in interfaceCommandMap
- 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
-
register
public 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
- Specified by:
register
in interfaceCommandMap
- 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
-
dispatch
public boolean dispatch(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String commandLine) throws CommandException
Looks for the requested command and executes it if found.- Specified by:
dispatch
in interfaceCommandMap
- Parameters:
sender
- The command's sendercommandLine
- 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
public void clearCommands()
Description copied from interface:CommandMap
Clears all registered commands.- Specified by:
clearCommands
in interfaceCommandMap
-
getCommand
@Nullable public @Nullable Command getCommand(@NotNull @NotNull String name)
Description copied from interface:CommandMap
Gets the command registered to the specified name- Specified by:
getCommand
in interfaceCommandMap
- 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 public @Nullable List<String> tabComplete(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String cmdLine)
Description copied from interface:CommandMap
Looks for the requested command and executes an appropriate tab-completer if found. This method will also tab-complete partial commands.- Specified by:
tabComplete
in interfaceCommandMap
- 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.
-
tabComplete
@Nullable public @Nullable List<String> tabComplete(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String cmdLine, @Nullable @Nullable Location location)
Description copied from interface:CommandMap
Looks for the requested command and executes an appropriate tab-completer if found. This method will also tab-complete partial commands.- Specified by:
tabComplete
in interfaceCommandMap
- 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.
-
getCommands
@NotNull public @NotNull Collection<Command> getCommands()
-
registerServerAliases
public void registerServerAliases()
-
-