Add Tab Completion loosely based on @TheUnnamedDude's work.
This commit is contained in:
@@ -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." );
|
||||
|
@@ -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);
|
||||
}
|
Reference in New Issue
Block a user