001 package org.bukkit.command;
002
003 import java.util.List;
004
005 public interface CommandMap {
006
007 /**
008 * Registers all the commands belonging to a certain plugin.
009 * <p>
010 * Caller can use:-
011 * <ul>
012 * <li>command.getName() to determine the label registered for this
013 * command
014 * <li>command.getAliases() to determine the aliases which where
015 * registered
016 * </ul>
017 *
018 * @param fallbackPrefix a prefix which is prepended to each command with
019 * a ':' one or more times to make the command unique
020 * @param commands a list of commands to register
021 */
022 public void registerAll(String fallbackPrefix, List<Command> commands);
023
024 /**
025 * Registers a command. Returns true on success; false if name is already
026 * taken and fallback had to be used.
027 * <p>
028 * Caller can use:-
029 * <ul>
030 * <li>command.getName() to determine the label registered for this
031 * command
032 * <li>command.getAliases() to determine the aliases which where
033 * registered
034 * </ul>
035 *
036 * @param label the label of the command, without the '/'-prefix.
037 * @param fallbackPrefix a prefix which is prepended to the command with a
038 * ':' one or more times to make the command unique
039 * @param command the command to register
040 * @return true if command was registered with the passed in label, false
041 * otherwise, which indicates the fallbackPrefix was used one or more
042 * times
043 */
044 public boolean register(String label, String fallbackPrefix, Command command);
045
046 /**
047 * Registers a command. Returns true on success; false if name is already
048 * taken and fallback had to be used.
049 * <p>
050 * Caller can use:-
051 * <ul>
052 * <li>command.getName() to determine the label registered for this
053 * command
054 * <li>command.getAliases() to determine the aliases which where
055 * registered
056 * </ul>
057 *
058 * @param fallbackPrefix a prefix which is prepended to the command with a
059 * ':' one or more times to make the command unique
060 * @param command the command to register, from which label is determined
061 * from the command name
062 * @return true if command was registered with the passed in label, false
063 * otherwise, which indicates the fallbackPrefix was used one or more
064 * times
065 */
066 public boolean register(String fallbackPrefix, Command command);
067
068 /**
069 * Looks for the requested command and executes it if found.
070 *
071 * @param sender The command's sender
072 * @param cmdLine command + arguments. Example: "/test abc 123"
073 * @return returns false if no target is found, true otherwise.
074 * @throws CommandException Thrown when the executor for the given command
075 * fails with an unhandled exception
076 */
077 public boolean dispatch(CommandSender sender, String cmdLine) throws CommandException;
078
079 /**
080 * Clears all registered commands.
081 */
082 public void clearCommands();
083
084 /**
085 * Gets the command registered to the specified name
086 *
087 * @param name Name of the command to retrieve
088 * @return Command with the specified name or null if a command with that
089 * label doesn't exist
090 */
091 public Command getCommand(String name);
092
093
094 /**
095 * Looks for the requested command and executes an appropriate
096 * tab-completer if found. This method will also tab-complete partial
097 * commands.
098 *
099 * @param sender The command's sender.
100 * @param cmdLine The entire command string to tab-complete, excluding
101 * initial slash.
102 * @return a list of possible tab-completions. This list may be immutable.
103 * Will be null if no matching command of which sender has permission.
104 * @throws CommandException Thrown when the tab-completer for the given
105 * command fails with an unhandled exception
106 * @throws IllegalArgumentException if either sender or cmdLine are null
107 */
108 public List<String> tabComplete(CommandSender sender, String cmdLine) throws IllegalArgumentException;
109 }