diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java b/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java index 6deff0d9..ebeb96dc 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java @@ -1,7 +1,10 @@ package pro.gravit.utils.command; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; +import org.jline.reader.Candidate; import pro.gravit.utils.helper.VerifyHelper; public abstract class Command { @@ -29,6 +32,29 @@ protected static UUID parseUUID(String s) throws CommandException { public abstract String getUsageDescription(); + public Candidate buildCandidate(CommandHandler.Category category, String commandName) + { + return new Candidate(commandName); + } + + public List complete(List words, int wordIndex, String word) + { + return new ArrayList<>(); + } + + public List subCommandComplete(String word, List commands) + { + List candidates = new ArrayList<>(); + for(String s : commands) + { + if(word.startsWith(s)) + { + candidates.add(new Candidate(s)); + } + } + return candidates; + } + public abstract void invoke(String... args) throws Exception; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java index 97566b37..a795c571 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java @@ -36,12 +36,20 @@ public class JLineConsoleCompleter implements Completer { @Override public void complete(LineReader reader, ParsedLine line, List candidates) { String completeWord = line.word(); - if (line.wordIndex() != 0) return; - walk((category, name, command) -> { - if (name.startsWith(completeWord)) { - candidates.add(new Candidate(name)); - } - }); + if (line.wordIndex() == 0) + { + walk((category, name, command) -> { + if (name.startsWith(completeWord)) { + candidates.add(command.buildCandidate(category, name)); + } + }); + } + else + { + Command target = findCommand(line.words().get(0)); + List candidates1 = target.complete(line.words(), line.wordIndex(), completeWord); + candidates.addAll(candidates1); + } } }