Add JvmName for 'static' members of CommandSender.Companion for a better Java API

This commit is contained in:
Him188 2020-08-31 13:01:19 +08:00
parent 8db2cd8e8f
commit 3001de5834

View File

@ -187,6 +187,7 @@ public interface CommandSender : CoroutineScope {
/** /**
* 构造 [FriendCommandSenderOnMessage] * 构造 [FriendCommandSenderOnMessage]
*/ */
@JvmName("from")
@JvmStatic @JvmStatic
public fun FriendMessageEvent.toCommandSender(): FriendCommandSenderOnMessage = public fun FriendMessageEvent.toCommandSender(): FriendCommandSenderOnMessage =
FriendCommandSenderOnMessage(this) FriendCommandSenderOnMessage(this)
@ -194,6 +195,7 @@ public interface CommandSender : CoroutineScope {
/** /**
* 构造 [MemberCommandSenderOnMessage] * 构造 [MemberCommandSenderOnMessage]
*/ */
@JvmName("from")
@JvmStatic @JvmStatic
public fun GroupMessageEvent.toCommandSender(): MemberCommandSenderOnMessage = public fun GroupMessageEvent.toCommandSender(): MemberCommandSenderOnMessage =
MemberCommandSenderOnMessage(this) MemberCommandSenderOnMessage(this)
@ -202,30 +204,34 @@ public interface CommandSender : CoroutineScope {
* 构造 [TempCommandSenderOnMessage] * 构造 [TempCommandSenderOnMessage]
*/ */
@JvmStatic @JvmStatic
@JvmName("from")
public fun TempMessageEvent.toCommandSender(): TempCommandSenderOnMessage = TempCommandSenderOnMessage(this) public fun TempMessageEvent.toCommandSender(): TempCommandSenderOnMessage = TempCommandSenderOnMessage(this)
/** /**
* 构造 [CommandSenderOnMessage] * 构造 [CommandSenderOnMessage]
*/ */
@JvmStatic @JvmStatic
@JvmName("from")
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
public fun <T : MessageEvent> T.toCommandSender(): CommandSenderOnMessage<T> = when (this) { public fun <T : MessageEvent> T.toCommandSender(): CommandSenderOnMessage<T> = when (this) {
is FriendMessageEvent -> toCommandSender() is FriendMessageEvent -> toCommandSender()
is GroupMessageEvent -> toCommandSender() is GroupMessageEvent -> toCommandSender()
is TempMessageEvent -> toCommandSender() is TempMessageEvent -> toCommandSender()
else -> throw IllegalArgumentException("unsupported MessageEvent: ${this::class.qualifiedNameOrTip}") else -> throw IllegalArgumentException("Unsupported MessageEvent: ${this::class.qualifiedNameOrTip}")
} as CommandSenderOnMessage<T> } as CommandSenderOnMessage<T>
/** /**
* 得到 [TempCommandSender] * 得到 [TempCommandSender]
*/ */
@JvmStatic @JvmStatic
@JvmName("of")
public fun Member.asTempCommandSender(): TempCommandSender = TempCommandSender(this) public fun Member.asTempCommandSender(): TempCommandSender = TempCommandSender(this)
/** /**
* 得到 [MemberCommandSender] * 得到 [MemberCommandSender]
*/ */
@JvmStatic @JvmStatic
@JvmName("of")
public fun Member.asMemberCommandSender(): MemberCommandSender = MemberCommandSender(this) public fun Member.asMemberCommandSender(): MemberCommandSender = MemberCommandSender(this)
/** /**
@ -234,6 +240,7 @@ public interface CommandSender : CoroutineScope {
* @see asMemberCommandSender * @see asMemberCommandSender
*/ */
@JvmStatic @JvmStatic
@JvmName("of")
public fun Member.asCommandSender(isTemp: Boolean): UserCommandSender { public fun Member.asCommandSender(isTemp: Boolean): UserCommandSender {
return if (isTemp) asTempCommandSender() else asMemberCommandSender() return if (isTemp) asTempCommandSender() else asMemberCommandSender()
} }
@ -242,6 +249,7 @@ public interface CommandSender : CoroutineScope {
* 得到 [FriendCommandSender] * 得到 [FriendCommandSender]
*/ */
@JvmStatic @JvmStatic
@JvmName("of")
public fun Friend.asCommandSender(): FriendCommandSender = FriendCommandSender(this) public fun Friend.asCommandSender(): FriendCommandSender = FriendCommandSender(this)
/** /**
@ -250,6 +258,7 @@ public interface CommandSender : CoroutineScope {
* @param isTemp * @param isTemp
*/ */
@JvmStatic @JvmStatic
@JvmName("of")
public fun User.asCommandSender(isTemp: Boolean): UserCommandSender = when (this) { public fun User.asCommandSender(isTemp: Boolean): UserCommandSender = when (this) {
is Friend -> this.asCommandSender() is Friend -> this.asCommandSender()
is Member -> if (isTemp) TempCommandSender(this) else MemberCommandSender(this) is Member -> if (isTemp) TempCommandSender(this) else MemberCommandSender(this)
@ -508,7 +517,7 @@ public abstract class ConsoleCommandSender @ConsoleFrontEndImplementation constr
return null return null
} }
override suspend fun sendMessage(message: String): MessageReceipt<User>? { public override suspend fun sendMessage(message: String): MessageReceipt<User>? {
MiraiConsoleImplementationBridge.consoleCommandSender.sendMessage(message) MiraiConsoleImplementationBridge.consoleCommandSender.sendMessage(message)
return null return null
} }