mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-07 08:58:20 +01:00
Detailed explanation of Argument, and basic comments for CommandSyntax
This commit is contained in:
parent
8d21352d5f
commit
59b03bf9ec
@ -4,7 +4,7 @@ import net.minestom.server.command.CommandSender;
|
|||||||
import net.minestom.server.command.builder.arguments.Argument;
|
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
|
@FunctionalInterface
|
||||||
public interface ArgumentCallback {
|
public interface ArgumentCallback {
|
||||||
|
@ -2,23 +2,41 @@ package net.minestom.server.command.builder;
|
|||||||
|
|
||||||
import net.minestom.server.command.builder.arguments.Argument;
|
import net.minestom.server.command.builder.arguments.Argument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a syntax in {@link Command}.
|
||||||
|
*/
|
||||||
public class CommandSyntax {
|
public class CommandSyntax {
|
||||||
|
|
||||||
private Argument[] args;
|
private final Argument[] args;
|
||||||
private CommandExecutor executor;
|
private CommandExecutor executor;
|
||||||
|
|
||||||
public CommandSyntax(Argument... args) {
|
protected CommandSyntax(Argument... args) {
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the required {@link Argument} for this sytnax
|
||||||
|
*
|
||||||
|
* @return the required arguments
|
||||||
|
*/
|
||||||
public Argument[] getArguments() {
|
public Argument[] getArguments() {
|
||||||
return args;
|
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() {
|
public CommandExecutor getExecutor() {
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the {@link CommandExecutor} of this syntax
|
||||||
|
*
|
||||||
|
* @param executor the new executor
|
||||||
|
*/
|
||||||
public void setExecutor(CommandExecutor executor) {
|
public void setExecutor(CommandExecutor executor) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
* An argument is meant to be parsed when added into a {@link Command} syntax.
|
||||||
* <p>
|
* <p>
|
||||||
* You can create your own with your own special conditions.
|
* You can create your own with your own special conditions.
|
||||||
|
* <p>
|
||||||
|
* 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 <T> the type of this parsed argument
|
* @param <T> the type of this parsed argument
|
||||||
*/
|
*/
|
||||||
@ -15,9 +20,9 @@ public abstract class Argument<T> {
|
|||||||
public static final int SUCCESS = 0;
|
public static final int SUCCESS = 0;
|
||||||
public static final int UNDEFINED_ERROR = -1;
|
public static final int UNDEFINED_ERROR = -1;
|
||||||
|
|
||||||
private String id;
|
private final String id;
|
||||||
private boolean allowSpace;
|
private final boolean allowSpace;
|
||||||
private boolean useRemaining;
|
private final boolean useRemaining;
|
||||||
|
|
||||||
private ArgumentCallback callback;
|
private ArgumentCallback callback;
|
||||||
|
|
||||||
@ -36,7 +41,7 @@ public abstract class Argument<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @param value The received argument
|
||||||
* @return The success/error code
|
* @return The success/error code
|
||||||
@ -44,7 +49,7 @@ public abstract class Argument<T> {
|
|||||||
public abstract int getCorrectionResult(String value);
|
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
|
* @param value The correct argument
|
||||||
* @return The parsed argument
|
* @return The parsed argument
|
||||||
@ -52,8 +57,8 @@ public abstract class Argument<T> {
|
|||||||
public abstract T parse(String value);
|
public abstract T parse(String value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Argument is at least partially correct (the syntax is good and the argument has been parsed)
|
* 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)
|
* but some other conditions could take place (ex: min/max requirement for numbers).
|
||||||
*
|
*
|
||||||
* @param value The parsed argument
|
* @param value The parsed argument
|
||||||
* @return The success/error code
|
* @return The success/error code
|
||||||
@ -92,7 +97,7 @@ public abstract class Argument<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @return the argument callback
|
||||||
*/
|
*/
|
||||||
@ -101,7 +106,7 @@ public abstract class Argument<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the {@link ArgumentCallback}
|
* Set the {@link ArgumentCallback}.
|
||||||
*
|
*
|
||||||
* @param callback the argument callback
|
* @param callback the argument callback
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user