Update JCommandManager; Add KDoc

This commit is contained in:
Karlatemp 2020-06-22 13:12:32 +08:00
parent 64d13f0a19
commit 68c0142765
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
2 changed files with 25 additions and 6 deletions

View File

@ -105,10 +105,10 @@ public final class JCommandManager {
* 解析并执行一个指令
*
* @param args 接受 {@link String} {@link Message} , 其他对象将会被 {@link Object#toString()}
* @return 是否成功解析到指令. 返回 `false` 代表无任何指令匹配
* @see CommandExecuteResult
* @see #executeCommandAsync(CoroutineScope, CommandSender, Object...)
*/
public static boolean executeCommand(final @NotNull CommandSender sender, final @NotNull Object... args) throws InterruptedException {
public static CommandExecuteResult executeCommand(final @NotNull CommandSender sender, final @NotNull Object... args) throws InterruptedException {
Objects.requireNonNull(sender, "sender");
Objects.requireNonNull(args, "args");
for (Object arg : args) {
@ -123,10 +123,10 @@ public final class JCommandManager {
*
* @param scope 协程作用域 (用于管理协程生命周期). 一般填入 {@link JavaPlugin} 实例.
* @param args 接受 {@link String} {@link Message} , 其他对象将会被 {@link Object#toString()}
* @return 是否成功解析到指令. 返回 `false` 代表无任何指令匹配
* @see CommandExecuteResult
* @see #executeCommand(CommandSender, Object...)
*/
public static CompletableFuture<Boolean> executeCommandAsync(final @NotNull CoroutineScope scope, final @NotNull CommandSender sender, final @NotNull Object... args) {
public static CompletableFuture<CommandExecuteResult> executeCommandAsync(final @NotNull CoroutineScope scope, final @NotNull CommandSender sender, final @NotNull Object... args) {
Objects.requireNonNull(sender, "sender");
Objects.requireNonNull(args, "args");
Objects.requireNonNull(scope, "scope");

View File

@ -134,7 +134,7 @@ fun Command.unregister(): Boolean = InternalCommandManager.modifyLock.withLock {
* Java 调用方式: `<static> CommandManager.executeCommand(Command)`
*
* @param messages 接受 [String] [Message], 其他对象将会被 [Any.toString]
* @return 是否成功解析到指令. 返回 `false` 代表无任何指令匹配
* @see CommandExecuteResult
*
* @see JCommandManager.executeCommand Java 方法
*/
@ -152,7 +152,7 @@ internal inline fun <reified T> List<T>.dropToTypedArray(n: Int): Array<T> = Arr
/**
* 解析并执行一个指令
* @return 是否成功解析到指令. 返回 `false` 代表无任何指令匹配
* @see CommandExecuteResult
*
* @see JCommandManager.executeCommand Java 方法
*/
@ -192,6 +192,14 @@ internal suspend inline fun CommandSender.executeCommandInternal(
/**
* 命令的执行返回
*
* @param status 命令最终执行状态
* @param exception 命令执行时发生的错误(如果有)
* @param command 尝试执行的命令 (status = SUCCESSFUL | FAILED)
* @param commandName 尝试执行的命令的名字 (status != EMPTY_COMMAND)
*
*
* @see CommandExecuteStatus
*/
class CommandExecuteResult(
val status: CommandExecuteStatus,
@ -201,10 +209,21 @@ class CommandExecuteResult(
) {
/**
* 命令的执行状态
*
* 当为 [SUCCESSFUL] 的时候代表命令执行成功
*
* 当为 [FAILED] 的时候, 代表命令执行出现了错误
*
* 当为 [COMMAND_NOT_FOUND] 的时候代表没有匹配的命令
*
* 当为 [EMPTY_COMMAND] 的时候, 代表尝试执行 ""
*
*/
enum class CommandExecuteStatus {
SUCCESSFUL, FAILED, COMMAND_NOT_FOUND, EMPTY_COMMAND
}
}
@Suppress("RemoveRedundantQualifierName")
typealias CommandExecuteStatus = CommandExecuteResult.CommandExecuteStatus