Majorly improved auto complete

This commit is contained in:
sekwah 2017-09-05 02:41:44 +01:00
parent 9ec4c3b78a
commit 7a747a86f9

View File

@ -37,7 +37,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
for(Material material : Material.values()) { for(Material material : Material.values()) {
this.blockMaterialList.add("triggerblock:" + material.name()); this.blockMaterialList.add("triggerblock:" + material.name().toLowerCase());
} }
plugin.getCommand("advancedportals").setExecutor(this); plugin.getCommand("advancedportals").setExecutor(this);
} }
@ -633,6 +633,15 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
/*System.out.printf("%s %s %s %s%n", sender, cmd, command, args);
System.out.println(args.length);
System.out.println("ARRAY");
for(String arg : args) {
System.out.println(arg);
}*/
LinkedList<String> autoComplete = new LinkedList<String>(); LinkedList<String> autoComplete = new LinkedList<String>();
if (sender.hasPermission("advancedportals.createportal")) { if (sender.hasPermission("advancedportals.createportal")) {
if (args.length == 1 || (args.length == 2 && args[0].toLowerCase().equals("help"))) { if (args.length == 1 || (args.length == 2 && args[0].toLowerCase().equals("help"))) {
@ -650,6 +659,23 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
// TODO change auto complete when quotes are opened and closed. Such as autocomplete @Player and stuff when specifying commands // TODO change auto complete when quotes are opened and closed. Such as autocomplete @Player and stuff when specifying commands
// For if partially complete found and also valid
boolean partialComplete = true;
// TODO add a better version of this to the new api.
//System.out.println(args[args.length - 1].equals(""));
String stillToComplete = args[args.length - 1];
if(stillToComplete.toLowerCase().startsWith("triggerblock:")) {
autoComplete.addAll(this.blockMaterialList);
}
else {
partialComplete = false;
}
if(!partialComplete) {
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
String argTag = getTag(args[i].toLowerCase()); String argTag = getTag(args[i].toLowerCase());
if (argTag.length() + 1 < args[i].length()) { if (argTag.length() + 1 < args[i].length()) {
@ -685,7 +711,6 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
} }
if (!hasTriggerBlock) { if (!hasTriggerBlock) {
autoComplete.add("triggerblock:"); autoComplete.add("triggerblock:");
autoComplete.addAll(this.blockMaterialList);
} }
if (!hasDestination) { if (!hasDestination) {
autoComplete.add("destination:"); autoComplete.add("destination:");
@ -700,6 +725,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (!hasCommand) { if (!hasCommand) {
autoComplete.add("command:"); autoComplete.add("command:");
} }
else {
autoComplete.add("@player");
}
}
} }
} }
Collections.sort(autoComplete); Collections.sort(autoComplete);