Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
68a9d492
Commit
68a9d492
authored
May 11, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a java way to broadcast an event
parent
f7533e3c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt
...core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt
+20
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt
View file @
68a9d492
...
...
@@ -12,9 +12,12 @@
package
net.mamoe.mirai.event
import
kotlinx.coroutines.CoroutineScope
import
net.mamoe.mirai.JavaFriendlyAPI
import
net.mamoe.mirai.event.internal.broadcastInternal
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.SinceMirai
import
net.mamoe.mirai.utils.internal.runBlocking
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmSynthetic
import
kotlin.jvm.Volatile
...
...
@@ -140,7 +143,9 @@ interface CancellableEvent : Event {
/**
* 广播一个事件的唯一途径.
* @see __broadcastJava
*/
@JvmSynthetic
suspend
fun
<
E
:
Event
>
E
.
broadcast
():
E
=
apply
{
if
(
this
is
BroadcastControllable
&&
!
this
.
shouldBroadcast
)
{
return
@
apply
...
...
@@ -148,6 +153,21 @@ suspend fun <E : Event> E.broadcast(): E = apply {
this
@
broadcast
.
broadcastInternal
()
// inline, no extra cost
}
/**
* 在 Java 广播一个事件的唯一途径.
*
* 调用方法: `EventKt.broadcast(event)`
*/
@Suppress
(
"FunctionName"
)
@JvmName
(
"broadcast"
)
@JavaFriendlyAPI
fun
<
E
:
Event
>
E
.
__broadcastJava
():
E
=
apply
{
if
(
this
is
BroadcastControllable
&&
!
this
.
shouldBroadcast
)
{
return
@
apply
}
runBlocking
{
this
@
__broadcastJava
.
broadcastInternal
()
}
}
/**
* 设置为 `true` 以关闭事件.
* 所有的 `subscribe` 都能正常添加到监听器列表, 但所有的广播都会直接返回.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment