Add Tab Completion loosely based on @TheUnnamedDude's work.

This commit is contained in:
md_5
2013-09-15 06:46:10 +10:00
parent 042f47cbb9
commit 29c897c9cf
6 changed files with 102 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.jar.JarEntry;
@@ -75,6 +76,11 @@ public class PluginManager
commandMap.values().remove( command );
}
public boolean dispatchCommand(CommandSender sender, String commandLine)
{
return dispatchCommand( sender, commandLine, null );
}
/**
* Execute a command if it is registered, else return false.
*
@@ -83,7 +89,7 @@ public class PluginManager
* arguments
* @return whether the command was handled
*/
public boolean dispatchCommand(CommandSender sender, String commandLine)
public boolean dispatchCommand(CommandSender sender, String commandLine, List<String> tabResults)
{
String[] split = argsSplit.split( commandLine );
// Check for chat that only contains " "
@@ -113,7 +119,13 @@ public class PluginManager
String[] args = Arrays.copyOfRange( split, 1, split.length );
try
{
command.execute( sender, args );
if ( tabResults == null )
{
command.execute( sender, args );
} else if ( command instanceof TabExecutor )
{
tabResults.addAll( ( (TabExecutor) command ).onTabComplete( sender, args ) );
}
} catch ( Exception ex )
{
sender.sendMessage( ChatColor.RED + "An internal error occurred whilst executing this command, please check the console log for details." );

View File

@@ -0,0 +1,11 @@
package net.md_5.bungee.api.plugin;
import net.md_5.bungee.api.CommandSender;
import java.util.List;
public interface TabExecutor
{
public List<String> onTabComplete(CommandSender sender, String[] args);
}