diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index 7af8a46..8dd4aec 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -21,10 +21,13 @@ package de.steamwar.command; import org.bukkit.command.CommandSender; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.function.Function; @@ -103,8 +106,33 @@ class SubCommand { } List tabComplete(CommandSender commandSender, String[] args) { - // TODO: implement tabCompleting for SubCommand - return null; + List argsList = Arrays.asList(args); + for (int i = 0; i < subCommand.length; i++) { + String s = argsList.remove(0); + if (argsList.isEmpty()) return Collections.singletonList(subCommand[i]); + if (!subCommand[i].equals(s)) return Collections.emptyList(); + } + for (int i = 0; i < arguments.length; i++) { + String s = argsList.remove(0); + if (argsList.isEmpty()) return arguments[i].tabCompletes(s); + try { + arguments[i].map(s); + } catch (Exception e) { + return Collections.emptyList(); + } + } + if (varArgs && !argsList.isEmpty()) { + while (!argsList.isEmpty()) { + String s = argsList.remove(0); + if (argsList.isEmpty()) return arguments[arguments.length - 1].tabCompletes(s); + try { + arguments[arguments.length - 1].map(s); + } catch (Exception e) { + return Collections.emptyList(); + } + } + } + return Collections.emptyList(); } }