Skip to content

Commit cf5e16f

Browse files
committed
KDoc: Modules
1 parent b7d2bee commit cf5e16f

File tree

8 files changed

+73
-11
lines changed

8 files changed

+73
-11
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package com.lambda.event
22

3+
/**
4+
* The [Muteable] interface represents any listening object that may need
5+
* to temporarily stop listening to events.
6+
*
7+
* Implementing this interface allows an object to
8+
* control its listening state through the [isMuted] property.
9+
* When [isMuted] is `true`, the object will not receive or process events.
10+
*
11+
* This can be useful in scenarios where an object's event handling behavior should be paused, for example,
12+
* when the object is in a certain state or when a specific condition is met.
13+
*
14+
* @property isMuted A flag indicating whether the object is currently muted.
15+
*/
316
interface Muteable {
417
val isMuted: Boolean
518
}

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,47 @@ import java.util.concurrent.ConcurrentHashMap
55
import java.util.concurrent.ConcurrentSkipListSet
66
import kotlin.reflect.KClass
77

8+
/**
9+
* The [Subscriber] class is a specialized [ConcurrentHashMap]
10+
* that manages sets of [Listener]s for different [Event] types.
11+
*
12+
* It provides methods to [subscribe] and [unsubscribe] [Listener]s and other [Subscriber]s.
13+
* It also allows for the merging of [Subscriber] [Set]s.
14+
*
15+
* @property defaultListenerSet A [ConcurrentSkipListSet] of [Listener]s, sorted in reverse order.
16+
*/
817
class Subscriber : ConcurrentHashMap<KClass<*>, ConcurrentSkipListSet<Listener>>() {
18+
val defaultListenerSet: ConcurrentSkipListSet<Listener>
19+
get() = ConcurrentSkipListSet(Comparator.reverseOrder())
20+
21+
22+
/** Allows a [Listener] to start receiving a specific type of [Event] */
923
inline fun <reified T : Event> subscribe(listener: Listener) =
10-
getOrPut(T::class) {
11-
defaultListenerSet()
12-
}.add(listener)
24+
getOrPut(T::class) { defaultListenerSet }.add(listener)
1325

26+
27+
/** Forgets about every [Listener]s association to [eventType] */
1428
fun unsubscribe(eventType: KClass<*>) = remove(eventType)
1529

30+
/** Allows a [Listener] to stop receiving a specific type of [Event] */
1631
fun unsubscribe(listener: Listener) {
1732
values.forEach { listeners ->
1833
listeners.remove(listener)
1934
}
2035
}
2136

37+
/** Allows a [Subscriber] to start receiving all [Event]s of another [Subscriber]. */
2238
infix fun subscribe(subscriber: Subscriber) {
2339
subscriber.forEach { (eventType, listeners) ->
24-
getOrPut(eventType) {
25-
defaultListenerSet()
26-
}.addAll(listeners)
40+
getOrPut(eventType) { defaultListenerSet }.addAll(listeners)
2741
}
2842
}
2943

44+
/** Allows a [Subscriber] to stop receiving all [Event]s of another [Subscriber] */
3045
infix fun unsubscribe(subscriber: Subscriber) {
3146
entries.removeAll { (eventType, listeners) ->
3247
subscriber[eventType]?.let { listeners.removeAll(it) }
3348
listeners.isEmpty()
3449
}
3550
}
36-
37-
fun defaultListenerSet(): ConcurrentSkipListSet<Listener> =
38-
ConcurrentSkipListSet(Comparator.reverseOrder())
3951
}

common/src/main/kotlin/com/lambda/module/ModuleConfig.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import com.lambda.config.Configuration
44
import com.lambda.util.FolderRegister
55
import java.io.File
66

7+
8+
/**
9+
* The [ModuleConfig] object represents the configuration file for the [Module]s.
10+
*
11+
* This object is used to save and load the settings of all [Module]s in the system.
12+
*
13+
* @property configName The name of the configuration.
14+
* @property primary The primary file where the configuration is saved.
15+
*/
716
object ModuleConfig : Configuration() {
817
override val configName = "modules"
918
override val primary = File(FolderRegister.config, "$configName.json")

common/src/main/kotlin/com/lambda/module/ModuleRegistry.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ package com.lambda.module
33
import com.lambda.event.events.ClientEvent
44
import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener
55
import org.reflections.Reflections
6+
import org.reflections.scanners.Scanners
67
import org.reflections.scanners.SubTypesScanner
78
import org.reflections.util.ClasspathHelper
89
import org.reflections.util.ConfigurationBuilder
910

11+
/**
12+
* The [ModuleRegistry] object is responsible for managing all [Module] instances in the system.
13+
*
14+
* @property modules A set of all [Module] instances in the system.
15+
*/
1016
object ModuleRegistry {
1117
private val modules = mutableSetOf<Module>()
1218

@@ -15,7 +21,7 @@ object ModuleRegistry {
1521
Reflections(
1622
ConfigurationBuilder()
1723
.setUrls(ClasspathHelper.forPackage("com.lambda.module.modules"))
18-
.setScanners(SubTypesScanner()) // ToDo: Deprecated, use Scanners.SubTypes instead
24+
.setScanners(Scanners.SubTypes)
1925
).getSubTypesOf(Module::class.java).forEach { moduleClass ->
2026
moduleClass.declaredFields.find {
2127
it.name == "INSTANCE"

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.lambda.event.listener.SafeListener.Companion.listener
66
import com.lambda.module.Module
77
import com.lambda.module.tag.ModuleTag
88
import com.lambda.util.KeyCode
9-
import net.minecraft.block.Blocks
109
import net.minecraft.util.math.BlockPos
1110

1211
object BoringModule : Module(

common/src/main/kotlin/com/lambda/module/tag/ModuleTag.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ package com.lambda.module.tag
22

33
import com.lambda.util.Nameable
44

5+
/**
6+
* The [ModuleTag] class represents a tag, that can be associated in any cardinality with a [Module].
7+
*
8+
* Tags are used to categorize and organize modules, making them easier to find.
9+
* They can be custom created as per the user's needs.
10+
*
11+
* Additionally, [ModuleTag] can be used to create groups of tags, which can be useful for creating new GUI windows.
12+
*
13+
* The companion object provides a set of predefined `ModuleTag` instances for common categories like "Combat",
14+
* "Movement", "Render", etc.
15+
*
16+
* @param name The name of the tag.
17+
*/
518
class ModuleTag(override val name: String) : Nameable {
619
companion object {
720
val COMBAT = ModuleTag("Combat")

common/src/main/kotlin/com/lambda/util/FolderRegister.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ package com.lambda.util
33
import com.lambda.Lambda.mc
44
import java.io.File
55

6+
/**
7+
* The [FolderRegister] object is responsible for managing the directory structure of the application.
8+
*
9+
* @property minecraft The root directory of the Minecraft client. It is retrieved using the `runDirectory` property of the Minecraft client instance.
10+
* @property lambda The directory for the Lambda client, located within the Minecraft directory.
11+
* @property config The directory for storing configuration files, located within the Lambda directory.
12+
*/
613
object FolderRegister {
714
val minecraft: File = mc.runDirectory
815
val lambda: File = File(minecraft, "lambda")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.lambda.util
22

3+
/**
4+
* @property name represents the name or identifier of the object.
5+
*/
36
interface Nameable {
47
val name: String
58
}

0 commit comments

Comments
 (0)