Skip to content

Commit 798a9c4

Browse files
committed
Fix listener skipping and improved module command
1 parent e554776 commit 798a9c4

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

common/src/main/kotlin/com/lambda/command/commands/ModuleCommand.kt

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package com.lambda.command.commands
22

3+
import com.lambda.brigadier.*
34
import com.lambda.brigadier.CommandResult.Companion.failure
45
import com.lambda.brigadier.CommandResult.Companion.success
56
import com.lambda.brigadier.argument.boolean
67
import com.lambda.brigadier.argument.string
78
import com.lambda.brigadier.argument.value
8-
import com.lambda.brigadier.executeWithResult
9-
import com.lambda.brigadier.get
10-
import com.lambda.brigadier.optional
11-
import com.lambda.brigadier.required
129
import com.lambda.command.CommandManager.prefix
1310
import com.lambda.command.CommandManager.register
1411
import com.lambda.command.LambdaCommand
@@ -25,6 +22,34 @@ object ModuleCommand : LambdaCommand() {
2522

2623
init {
2724
register(name, "mod") {
25+
executeWithResult {
26+
val enabled = ModuleRegistry.modules.filter {
27+
it.isEnabled
28+
}
29+
30+
if (enabled.isEmpty()) {
31+
info("No modules are enabled")
32+
return@executeWithResult success()
33+
}
34+
35+
this@ModuleCommand.info(buildText {
36+
styled(Color.GREY) {
37+
literal("Enabled Modules: ")
38+
}
39+
enabled.forEachIndexed { index, module ->
40+
if (index != 0) {
41+
literal(", ")
42+
}
43+
clickEvent(suggestCommand("$prefix${input} ${module.name}")) {
44+
styled(if (module.isEnabled) Color.GREEN else Color.RED) {
45+
literal(module.name)
46+
}
47+
}
48+
}
49+
})
50+
return@executeWithResult success()
51+
}
52+
2853
required(string("module name")) { moduleName ->
2954
suggests { _, builder ->
3055
ModuleRegistry.modules.map {

common/src/main/kotlin/com/lambda/event/EventFlow.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.lambda.event
22

3+
import com.lambda.Lambda.LOG
34
import com.lambda.event.cancellable.ICancellable
45
import com.lambda.event.listener.Listener
56
import com.lambda.threading.runConcurrent
7+
import com.lambda.util.Communication.info
68
import kotlinx.coroutines.CoroutineScope
79
import kotlinx.coroutines.Dispatchers
810
import kotlinx.coroutines.Job
@@ -84,25 +86,23 @@ object EventFlow {
8486

8587
private fun Event.executeListenerSynchronous() {
8688
syncListeners[this::class]?.forEach { listener ->
87-
if (listener.owner is Muteable
88-
&& (listener.owner as Muteable).isMuted
89-
&& !listener.alwaysListen
90-
) return
91-
if (this is ICancellable && this.isCanceled()) return
92-
listener.execute(this@executeListenerSynchronous)
89+
if (shouldNotNotify(listener, this)) return@forEach
90+
listener.execute(this)
9391
}
9492
}
9593

9694
private fun Event.executeListenerConcurrently() {
9795
concurrentListeners[this::class]?.forEach { listener ->
98-
if (listener.owner is Muteable
99-
&& (listener.owner as Muteable).isMuted
100-
&& !listener.alwaysListen
101-
) return
102-
if (this is ICancellable && this.isCanceled()) return
96+
if (shouldNotNotify(listener, this)) return@forEach
10397
runConcurrent {
104-
listener.execute(this@executeListenerConcurrently)
98+
listener.execute(this)
10599
}
106100
}
107101
}
102+
103+
private fun shouldNotNotify(listener: Listener, event: Event) =
104+
listener.owner is Muteable
105+
&& (listener.owner as Muteable).isMuted
106+
&& !listener.alwaysListen
107+
|| event is ICancellable && event.isCanceled()
108108
}

common/src/main/kotlin/com/lambda/event/listener/SafeListener.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,6 @@ class SafeListener(
173173
return listener
174174
}
175175
}
176+
177+
override fun toString() = "SafeListener(priority=$priority, owner=${owner::class.simpleName}, alwaysListen=$alwaysListen)"
176178
}

common/src/main/kotlin/com/lambda/module/modules/BoringModule.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ object BoringModule : Module(
3939
init {
4040
onEnable {
4141
LOG.info("I'm was enabled!")
42-
toast("I'm enabled!")
4342
}
4443

4544
onDisable {
@@ -51,7 +50,7 @@ object BoringModule : Module(
5150
}
5251

5352
listener<TickEvent.Pre> {
54-
this@BoringModule.info("I'm ${if (superBoring) "super boring ($boringValue)" else "boring"}!")
53+
LOG.info("I'm ${if (superBoring) "super boring ($boringValue)" else "boring"}!")
5554
}
5655
}
5756
}

0 commit comments

Comments
 (0)