14c7734fb1
CommandMap contains a method that will auto-complete commands appropriately. Before the first space, it searches for commands of which the sender has permission. After the first space, it delegates to the individual command. Vanilla commands contain implementations to mimic vanilla implementation. Exception would be give, that allows for name matching; a feature we already allowed as part of the command is now supported for auto-complete as well. Plugin commands can get a tab completer set to delegate the completion for. If no tab completer is set, it can check the executor to see if it implements the tab completion interface. It will also attempt to chain calls if null gets returned from these interfaces. Plugins also implement the new TabCompleter interface, to add ease-of-use for plugin developers, similar to the onCommand() method. The default command implementation simply searches for player names. To help facilitate command completion, a utility class was added with two functions. One checks two strings, to see if the specified string starts with (ignoring case) the second. The other method uses the first to selectively copy elements from one collection to another. By: Score_Under <seejay.11@gmail.com>
78 lines
3.7 KiB
Java
78 lines
3.7 KiB
Java
package org.bukkit.command;
|
|
|
|
import java.util.List;
|
|
|
|
public interface CommandMap {
|
|
|
|
/**
|
|
* 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
|
|
*
|
|
* @param fallbackPrefix a prefix which is prepended to each command with a ':' one or more times to make the command unique
|
|
* @param commands a list of commands to register
|
|
*/
|
|
public void registerAll(String fallbackPrefix, List<Command> commands);
|
|
|
|
/**
|
|
* 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
|
|
*
|
|
* @param label the label of the command, without the '/'-prefix.
|
|
* @param fallbackPrefix a prefix which is prepended to the command with a ':' one or more times to make the command unique
|
|
* @param command the command to register
|
|
* @return true if command was registered with the passed in label, false otherwise, which indicates the fallbackPrefix was used one or more times
|
|
*/
|
|
public boolean register(String label, String fallbackPrefix, 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
|
|
*
|
|
* @param fallbackPrefix a prefix which is prepended to the command with a ':' one or more times to make the command unique
|
|
* @param command the command to register, from which label is determined from the command name
|
|
* @return true if command was registered with the passed in label, false otherwise, which indicates the fallbackPrefix was used one or more times
|
|
*/
|
|
public boolean register(String fallbackPrefix, Command command);
|
|
|
|
/**
|
|
* Looks for the requested command and executes it if found.
|
|
*
|
|
* @param sender The command's sender
|
|
* @param cmdLine command + arguments. Example: "/test abc 123"
|
|
* @return returns false if no target is found, true otherwise.
|
|
* @throws CommandException Thrown when the executor for the given command fails with an unhandled exception
|
|
*/
|
|
public boolean dispatch(CommandSender sender, String cmdLine) throws CommandException;
|
|
|
|
/**
|
|
* Clears all registered commands.
|
|
*/
|
|
public void clearCommands();
|
|
|
|
/**
|
|
* Gets the command registered to the specified name
|
|
*
|
|
* @param name Name of the command to retrieve
|
|
* @return Command with the specified name or null if a command with that label doesn't exist
|
|
*/
|
|
public Command getCommand(String name);
|
|
|
|
|
|
/**
|
|
* Looks for the requested command and executes an appropriate tab-completer if found. This method will also tab-complete partial commands.
|
|
*
|
|
* @param sender The command's sender.
|
|
* @param cmdLine The entire command string to tab-complete, excluding initial slash.
|
|
* @return 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 exception
|
|
* @throws IllegalArgumentException if either sender or cmdLine are null
|
|
*/
|
|
public List<String> tabComplete(CommandSender sender, String cmdLine) throws IllegalArgumentException;
|
|
}
|