Add extensions for CommandSender.execute(Command,...)

This commit is contained in:
Him188 2020-09-12 19:06:05 +08:00
parent 3a45254fee
commit 79136a2666

View File

@ -104,7 +104,7 @@ public interface CommandManager {
@JvmBlockingBridge @JvmBlockingBridge
public suspend fun CommandSender.executeCommand( public suspend fun CommandSender.executeCommand(
message: Message, message: Message,
checkPermission: Boolean = true checkPermission: Boolean = true,
): CommandExecuteResult ): CommandExecuteResult
/** /**
@ -120,7 +120,7 @@ public interface CommandManager {
@JvmBlockingBridge @JvmBlockingBridge
public suspend fun CommandSender.executeCommand( public suspend fun CommandSender.executeCommand(
message: String, message: String,
checkPermission: Boolean = true checkPermission: Boolean = true,
): CommandExecuteResult = executeCommand(PlainText(message).asMessageChain(), checkPermission) ): CommandExecuteResult = executeCommand(PlainText(message).asMessageChain(), checkPermission)
/** /**
@ -132,7 +132,7 @@ public interface CommandManager {
public suspend fun Command.execute( public suspend fun Command.execute(
sender: CommandSender, sender: CommandSender,
arguments: Message = EmptyMessageChain, arguments: Message = EmptyMessageChain,
checkPermission: Boolean = true checkPermission: Boolean = true,
): CommandExecuteResult ): CommandExecuteResult
/** /**
@ -145,7 +145,7 @@ public interface CommandManager {
public suspend fun Command.execute( public suspend fun Command.execute(
sender: CommandSender, sender: CommandSender,
arguments: String = "", arguments: String = "",
checkPermission: Boolean = true checkPermission: Boolean = true,
): CommandExecuteResult = execute(sender, PlainText(arguments).asMessageChain(), checkPermission) ): CommandExecuteResult = execute(sender, PlainText(arguments).asMessageChain(), checkPermission)
public companion object INSTANCE : CommandManager by CommandManagerImpl { public companion object INSTANCE : CommandManager by CommandManagerImpl {
@ -165,24 +165,48 @@ public interface CommandManager {
override suspend fun Command.execute( override suspend fun Command.execute(
sender: CommandSender, sender: CommandSender,
arguments: Message, arguments: Message,
checkPermission: Boolean checkPermission: Boolean,
): CommandExecuteResult = ): CommandExecuteResult =
CommandManagerImpl.run { execute(sender, arguments = arguments, checkPermission = checkPermission) } CommandManagerImpl.run { execute(sender, arguments = arguments, checkPermission = checkPermission) }
override suspend fun CommandSender.executeCommand( override suspend fun CommandSender.executeCommand(
message: String, message: String,
checkPermission: Boolean checkPermission: Boolean,
): CommandExecuteResult = CommandManagerImpl.run { executeCommand(message, checkPermission) } ): CommandExecuteResult = CommandManagerImpl.run { executeCommand(message, checkPermission) }
override suspend fun Command.execute( override suspend fun Command.execute(
sender: CommandSender, sender: CommandSender,
arguments: String, arguments: String,
checkPermission: Boolean checkPermission: Boolean,
): CommandExecuteResult = CommandManagerImpl.run { execute(sender, arguments, checkPermission) } ): CommandExecuteResult = CommandManagerImpl.run { execute(sender, arguments, checkPermission) }
override suspend fun CommandSender.executeCommand( override suspend fun CommandSender.executeCommand(
message: Message, message: Message,
checkPermission: Boolean checkPermission: Boolean,
): CommandExecuteResult = CommandManagerImpl.run { executeCommand(message, checkPermission) } ): CommandExecuteResult = CommandManagerImpl.run { executeCommand(message, checkPermission) }
/**
* 执行一个确切的指令
* @see execute 获取更多信息
*/
public suspend fun CommandSender.execute(
command: Command,
arguments: Message,
checkPermission: Boolean = true,
): CommandExecuteResult {
return command.execute(this, arguments, checkPermission)
}
/**
* 执行一个确切的指令
* @see execute 获取更多信息
*/
public suspend fun CommandSender.execute(
command: Command,
arguments: String,
checkPermission: Boolean = true,
): CommandExecuteResult {
return command.execute(this, arguments, checkPermission)
}
} }
} }