From 31356af2131d1fc18fa363a04fee2260dd33c854 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 28 Aug 2019 18:18:57 +0700 Subject: [PATCH] =?UTF-8?q?[DOC]=20=D0=94=D0=BE=D0=BA=D1=83=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BA=20Command/Command?= =?UTF-8?q?Handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/utils/command/Command.java | 28 +++++++++++++++++++ .../gravit/utils/command/CommandHandler.java | 22 +++++++++++++++ 2 files changed, 50 insertions(+) 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 aa1470ac..f6e220dc 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java @@ -6,6 +6,9 @@ import pro.gravit.utils.helper.VerifyHelper; public abstract class Command { + /** + * List of available subcommands + */ public Map childCommands; public Command() { @@ -38,11 +41,24 @@ protected static UUID parseUUID(String s) throws CommandException { public abstract String getUsageDescription(); + /** + * Creates a JLine candidate that appears in the list of available options when you press TAB + * @param category this command category + * @param commandName this command name + * @return JLine Candidate + */ public Candidate buildCandidate(CommandHandler.Category category, String commandName) { return new Candidate(commandName); } + /** + * Returns a list of available options for the next word for the current command. + * @param words list all user words + * @param wordIndex current word index + * @param word current word + * @return list of available Candidate + */ public List complete(List words, int wordIndex, String word) { if(wordIndex == 0) @@ -64,6 +80,12 @@ public List complete(List words, int wordIndex, String word) } } + /** + * Transfer control to subcommands + * @param args command arguments(includes subcommand name) + * @throws Exception + * Error executing command + */ public void invokeSubcommands(String... args) throws Exception { verifyArgs(args, 1); @@ -73,6 +95,12 @@ public void invokeSubcommands(String... args) throws Exception } + /** + * Run current command + * @param args command arguments + * @throws Exception + * Error executing command + */ public abstract void invoke(String... args) throws Exception; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java index d52168e2..3dd09559 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java @@ -90,6 +90,12 @@ public Command findCommand(String name) { } + /** + * Reads a line from the console + * @return command line + * @throws IOException + * Internal Error + */ public abstract String readLine() throws IOException; private void readLoop() throws IOException { @@ -133,6 +139,12 @@ public interface CommandWalk { void walk(Category category, String name, Command command); } + /** + * Walk all categories + * Categories are sorted in the order they are added. + * The base category is walked last + * @param callback your callback + */ public void walk(CommandWalk callback) { for (CommandHandler.Category category : getCategories()) { for (Map.Entry entry : category.category.commandsMap().entrySet()) @@ -150,8 +162,18 @@ public List getCategories() { return categories; } + /** + * If supported, sends a bell signal to the console + * @throws IOException + * Internal Error + */ public abstract void bell() throws IOException; + /** + * Cleans the console + * @throws IOException + * Internal Error + */ public abstract void clear() throws IOException; }