fixed tab completion

This commit is contained in:
boy0001 2014-11-03 17:53:10 +11:00
parent 5c24fc092d
commit 9fcab4ba87

View File

@ -12,6 +12,7 @@ import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.StringComparsion; import com.intellectualcrafters.plot.StringComparsion;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -208,22 +209,32 @@ public class MainCommand implements CommandExecutor, TabCompleter {
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
if(!(commandSender instanceof Player)) return null; if(!(commandSender instanceof Player)) return null;
Player player = (Player) commandSender; Player player = (Player) commandSender;
ArrayList<SubCommand> subo = subCommands;
if(strings.length < 1 || strings[0].length() < 2) return null; if(strings.length < 1) {
while(true) { if (strings.length==0 || "plots".startsWith(s)) {
String sub = new StringComparsion(strings[0], subo.toArray()).getBestMatch(); return Arrays.asList(new String[] {"plots"});
if(subo.isEmpty()) }
break; }
for (SubCommand subCommand : subo) { if (strings.length > 1) {
if (subCommand.cmd.equals(sub)) { return null;
if(subCommand.permission.hasPermission(player)) }
return Arrays.asList(sub); if (!command.getLabel().equalsIgnoreCase("plots")) {
else { return null;
subo.remove(subCommand); }
break; List<String> tabOptions = new ArrayList<String>();
String arg = strings[0].toLowerCase();
for (SubCommand cmd : subCommands) {
if (cmd.permission.hasPermission(player)) {
if (cmd.cmd.startsWith(arg)) {
tabOptions.add(cmd.cmd);
}
else if (cmd.alias.startsWith(arg)) {
tabOptions.add(cmd.alias);
} }
} }
} }
if(tabOptions.size()>0) {
return tabOptions;
} }
return null; return null;
} }