From 59b03bf9ec1de37ac146b820b4964942f83e1d52 Mon Sep 17 00:00:00 2001 From: themode Date: Thu, 15 Oct 2020 15:19:07 +0200 Subject: [PATCH] Detailed explanation of Argument, and basic comments for CommandSyntax --- .../command/builder/ArgumentCallback.java | 2 +- .../server/command/builder/CommandSyntax.java | 22 ++++++++++++++++-- .../command/builder/arguments/Argument.java | 23 +++++++++++-------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/minestom/server/command/builder/ArgumentCallback.java b/src/main/java/net/minestom/server/command/builder/ArgumentCallback.java index aab58802e..bf1c0dfe4 100644 --- a/src/main/java/net/minestom/server/command/builder/ArgumentCallback.java +++ b/src/main/java/net/minestom/server/command/builder/ArgumentCallback.java @@ -4,7 +4,7 @@ import net.minestom.server.command.CommandSender; import net.minestom.server.command.builder.arguments.Argument; /** - * Callback executed when an error is found within the {@link Argument} + * Callback executed when an error is found within the {@link Argument}. */ @FunctionalInterface public interface ArgumentCallback { diff --git a/src/main/java/net/minestom/server/command/builder/CommandSyntax.java b/src/main/java/net/minestom/server/command/builder/CommandSyntax.java index 9a6c255ae..f452a372e 100644 --- a/src/main/java/net/minestom/server/command/builder/CommandSyntax.java +++ b/src/main/java/net/minestom/server/command/builder/CommandSyntax.java @@ -2,23 +2,41 @@ package net.minestom.server.command.builder; import net.minestom.server.command.builder.arguments.Argument; +/** + * Represents a syntax in {@link Command}. + */ public class CommandSyntax { - private Argument[] args; + private final Argument[] args; private CommandExecutor executor; - public CommandSyntax(Argument... args) { + protected CommandSyntax(Argument... args) { this.args = args; } + /** + * Get all the required {@link Argument} for this sytnax + * + * @return the required arguments + */ public Argument[] getArguments() { return args; } + /** + * Get the {@link CommandExecutor} of this syntax, executed once the syntax is properly wrote. + * + * @return the executor of this syntax + */ public CommandExecutor getExecutor() { return executor; } + /** + * Change the {@link CommandExecutor} of this syntax + * + * @param executor the new executor + */ public void setExecutor(CommandExecutor executor) { this.executor = executor; } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/Argument.java b/src/main/java/net/minestom/server/command/builder/arguments/Argument.java index 40f418ca9..dc9f16af5 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/Argument.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/Argument.java @@ -7,6 +7,11 @@ import net.minestom.server.command.builder.Command; * An argument is meant to be parsed when added into a {@link Command} syntax. *

* You can create your own with your own special conditions. + *

+ * Here in order, how is parsed an argument: {@link #getCorrectionResult(String)} to check + * if the syntax is correct, {@link #parse(String)} to convert the correct argument + * and {@link #getConditionResult(Object)} to verify that the parsed object validate the additional + * conditions. * * @param the type of this parsed argument */ @@ -15,9 +20,9 @@ public abstract class Argument { public static final int SUCCESS = 0; public static final int UNDEFINED_ERROR = -1; - private String id; - private boolean allowSpace; - private boolean useRemaining; + private final String id; + private final boolean allowSpace; + private final boolean useRemaining; private ArgumentCallback callback; @@ -36,7 +41,7 @@ public abstract class Argument { } /** - * Used to provide the appropriate error concerning the args received + * Used to provide the appropriate error concerning the received args. * * @param value The received argument * @return The success/error code @@ -44,7 +49,7 @@ public abstract class Argument { public abstract int getCorrectionResult(String value); /** - * The argument syntax is correct, parsed here to the correct type + * The argument syntax is correct, parsed here to the correct type. * * @param value The correct argument * @return The parsed argument @@ -52,8 +57,8 @@ public abstract class Argument { public abstract T parse(String value); /** - * Argument is at least partially correct (the syntax is good and the argument has been parsed) - * but some other conditions could take place (ex: min/max requirement for numbers) + * The argument is at least partially correct (the syntax is good and the argument has been parsed) + * but some other conditions could take place (ex: min/max requirement for numbers). * * @param value The parsed argument * @return The success/error code @@ -92,7 +97,7 @@ public abstract class Argument { } /** - * Get the argument callback to check if the argument-specific conditions are validated or not + * Get the {@link ArgumentCallback} to check if the argument-specific conditions are validated or not. * * @return the argument callback */ @@ -101,7 +106,7 @@ public abstract class Argument { } /** - * Set the {@link ArgumentCallback} + * Set the {@link ArgumentCallback}. * * @param callback the argument callback */