Add tab-completion API. Fixes BUKKIT-2181. Adds BUKKIT-2602

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>
This commit is contained in:
Bukkit/Spigot
2012-10-09 14:54:12 -05:00
parent 74f83f3098
commit 14c7734fb1
43 changed files with 904 additions and 51 deletions

View File

@@ -5,7 +5,7 @@ import java.io.InputStream;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.TabExecutor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.generator.ChunkGenerator;
@@ -16,7 +16,7 @@ import com.avaje.ebean.EbeanServer;
* <p />
* The use of {@link PluginBase} is recommended for actual Implementation
*/
public interface Plugin extends CommandExecutor {
public interface Plugin extends TabExecutor {
/**
* Returns the folder that the plugin data's files are located in. The
* folder may not yet exist.

View File

@@ -298,6 +298,13 @@ public abstract class JavaPlugin extends PluginBase {
return false;
}
/**
* {@inheritDoc}
*/
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return null;
}
/**
* Gets the command with the given name, specific to this plugin
*