Skip to content

Commit 2e7ea28

Browse files
committed
Lots of new KDocs
1 parent bbccf01 commit 2e7ea28

File tree

12 files changed

+192
-6
lines changed

12 files changed

+192
-6
lines changed

common/src/main/kotlin/com/lambda/context/AbstractContext.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import net.minecraft.client.network.ClientPlayerEntity
66
import net.minecraft.client.network.ClientPlayerInteractionManager
77
import net.minecraft.client.world.ClientWorld
88

9+
/**
10+
* Representing an abstract context in the [MinecraftClient].
11+
*
12+
* @property mc The Minecraft client instance.
13+
* @property world The world in which the player is currently located, or `null` if the world is not available.
14+
* @property player The player entity, or `null` if the player is not available.
15+
* @property interaction The interaction manager for the player, or `null` if the interaction manager is not available.
16+
* @property connection The network handler for the player, or `null` if the network handler is not available.
17+
*/
918
abstract class AbstractContext {
1019
val mc: MinecraftClient = MinecraftClient.getInstance()
1120
abstract val world: ClientWorld?

common/src/main/kotlin/com/lambda/context/ClientContext.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ import net.minecraft.client.network.ClientPlayNetworkHandler
44
import net.minecraft.client.network.ClientPlayerEntity
55
import net.minecraft.client.network.ClientPlayerInteractionManager
66
import net.minecraft.client.world.ClientWorld
7+
import net.minecraft.client.MinecraftClient
78

9+
/**
10+
* A class extending the [AbstractContext] in the [MinecraftClient].
11+
* This is considered the "unsafe" variant of the contexts as the properties can be null.
12+
* Methods in this context will always need to perform null checks for type safety.
13+
*
14+
* @property world The world in which the player is currently located, or `null` if the world is not available.
15+
* @property player The player entity, or `null` if the player is not available.
16+
* @property interaction The interaction manager for the player, or `null` if the interaction manager is not available.
17+
* @property connection The network handler for the player, or `null` if the network handler is not available.
18+
*
19+
* @function toSafe Converts the `ClientContext` to a `SafeContext` if all properties are not `null`, or returns `null` otherwise.
20+
*/
821
open class ClientContext : AbstractContext() {
922
final override val world: ClientWorld? = mc.world
1023
final override val player: ClientPlayerEntity? = mc.player

common/src/main/kotlin/com/lambda/context/SafeContext.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,31 @@ import net.minecraft.client.network.ClientPlayNetworkHandler
44
import net.minecraft.client.network.ClientPlayerEntity
55
import net.minecraft.client.network.ClientPlayerInteractionManager
66
import net.minecraft.client.world.ClientWorld
7+
import net.minecraft.client.MinecraftClient
78

9+
/**
10+
* A class extending the [AbstractContext] in the [MinecraftClient].
11+
* This is considered the "safe" variant of the contexts as the properties are non-`null`.
12+
* Methods in this context will not need to perform `null` checks for type safety.
13+
*
14+
* The [SafeContext] is used as a receiver in extension functions to bring the type-safe properties into scope.
15+
* This allows methods to operate on the [MinecraftClient] without the need for type checks on the properties.
16+
*
17+
* Example usage:
18+
* ```kotlin
19+
* fun SafeContext.exampleFunction() {
20+
* // Here, we can directly access the properties without null checks
21+
* val playerName = player.name.asString()
22+
* val worldName = world.registryKey.value.path
23+
* // ...
24+
* }
25+
* ```
26+
*
27+
* @property world The world in which the player is currently located.
28+
* @property player The player entity.
29+
* @property interaction The interaction manager for the player.
30+
* @property connection The network handler for the player.
31+
**/
832
open class SafeContext internal constructor(
933
override val world: ClientWorld,
1034
override val player: ClientPlayerEntity,

common/src/main/kotlin/com/lambda/event/cancellable/Cancellable.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ package com.lambda.event.cancellable
22

33
import java.util.concurrent.atomic.AtomicBoolean
44

5+
/**
6+
* Used as delegate for [ICancellable] events.
7+
*
8+
* A `Cancellable` event is a type of [ICancellable] that can be cancelled.
9+
* It has a [cancelSignal] which is an [AtomicBoolean] that indicates whether the event has been canceled.
10+
*
11+
* @property cancelSignal The signal that indicates whether the event has been canceled.
12+
*/
513
open class Cancellable : ICancellable {
614
override val cancelSignal = AtomicBoolean(false)
715
}

common/src/main/kotlin/com/lambda/event/cancellable/ICancellable.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@ package com.lambda.event.cancellable
33
import com.lambda.event.CallbackEvent
44
import java.util.concurrent.atomic.AtomicBoolean
55

6+
/**
7+
* Representing a cancellable [CallbackEvent] in the event system.
8+
*
9+
* An [ICancellable] event is a type of [CallbackEvent] that can be canceled using [cancel].
10+
* It has a [cancelSignal] which is an [AtomicBoolean] that indicates whether the event has been canceled.
11+
*
12+
* @property cancelSignal The signal that indicates whether the event has been canceled.
13+
*/
614
interface ICancellable : CallbackEvent {
715
val cancelSignal: AtomicBoolean
816

17+
/**
18+
* Cancels the event.
19+
*/
920
fun cancel() {
1021
cancelSignal.set(true)
1122
}
1223

24+
/**
25+
* Checks whether the event has been canceled.
26+
*/
1327
fun isCanceled() = cancelSignal.get()
1428
}

common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import com.lambda.module.Module
88
abstract class ClientEvent : Event {
99
data object Shutdown : ClientEvent()
1010
data object Startup : ClientEvent()
11-
data class ModuleToggle(val module: Module) : ClientEvent()
12-
data class ModuleEnable(val module: Module) : ClientEvent()
13-
data class ModuleDisable(val module: Module) : ClientEvent()
1411
data class ConfigLoaded(val configuration: Configuration) : ClientEvent()
1512
data class ConfigSaved(val configuration: Configuration) : ClientEvent()
1613
}

common/src/main/kotlin/com/lambda/event/events/KeyPressEvent.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,14 @@ package com.lambda.event.events
22

33
import com.lambda.event.cancellable.Cancellable
44
import com.lambda.event.cancellable.ICancellable
5+
import com.lambda.event.EventFlow
56

7+
/**
8+
* A class representing a [KeyPressEvent] in the event system ([EventFlow]).
9+
*
10+
* A [KeyPressEvent] is a type of event that is triggered when a key is pressed.
11+
* It implements [ICancellable] interface, which means the event can be cancelled.
12+
*
13+
* @property key The key code of the key that was pressed.
14+
*/
615
class KeyPressEvent(val key: Int) : ICancellable by Cancellable()

common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,37 @@ import com.lambda.event.Event
44
import com.lambda.event.cancellable.Cancellable
55
import com.lambda.event.cancellable.ICancellable
66
import net.minecraft.network.packet.Packet
7+
import com.lambda.event.EventFlow
78

9+
/**
10+
* An abstract class representing a [PacketEvent] in the [EventFlow].
11+
*
12+
* A [PacketEvent] is a type of [Event] that is triggered when a packet is sent or received.
13+
* It has two subclasses: [Send] and [Receive],
14+
* which are triggered when a packet is sent and received, respectively.
15+
*
16+
* Each subclass has two further subclasses: [Pre] and [Post],
17+
* which are triggered before and after the packet is sent or received.
18+
*
19+
* The [PacketEvent] class is designed to be extended by any class that needs to react to packet events.
20+
*
21+
* @see Send
22+
* @see Receive
23+
*/
824
abstract class PacketEvent : Event {
25+
/**
26+
* Representing a [PacketEvent] that is triggered when a packet is sent.
27+
* It has two subclasses: [Pre] and [Post], which are triggered before and after the packet is sent.
28+
*/
929
abstract class Send : PacketEvent() {
1030
class Pre(val packet: Packet<*>) : Send(), ICancellable by Cancellable()
1131
class Post(val packet: Packet<*>) : Send()
1232
}
1333

34+
/**
35+
* Representing a `PacketEvent` that is triggered when a packet is received.
36+
* It has two subclasses: [Pre] and [Post], which are triggered before and after the packet is received.
37+
*/
1438
abstract class Receive : PacketEvent() {
1539
class Pre(val packet: Packet<*>) : Receive(), ICancellable by Cancellable()
1640
class Post(val packet: Packet<*>) : Receive()
17-
}
18-
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
package com.lambda.event.events
22

33
import com.lambda.event.Event
4+
import com.lambda.event.EventFlow
45

6+
/**
7+
* An abstract class representing a [TickEvent] in the [EventFlow].
8+
*
9+
* A [TickEvent] is a type of [Event] that is triggered at each tick of the game loop.
10+
* It has two subclasses: [Pre] and [Post], which are triggered before and after the tick, respectively.
11+
*
12+
* The [TickEvent] class is designed to be extended by any class that needs to react to ticks.
13+
*
14+
* @see Pre
15+
* @see Post
16+
*/
517
abstract class TickEvent : Event {
18+
/**
19+
* A class representing a [TickEvent] that is triggered before each tick of the game loop.
20+
*/
621
class Pre : TickEvent()
22+
23+
/**
24+
* A class representing a [TickEvent] that is triggered after each tick of the game loop.
25+
*/
726
class Post : TickEvent()
827
}

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,52 @@
11
package com.lambda.event.listener
22

33
import com.lambda.event.Event
4+
import com.lambda.event.EventFlow
5+
import com.lambda.event.Muteable
6+
import com.lambda.module.Module
47

8+
/**
9+
* An abstract class representing a [Listener] in the [Event] system ([EventFlow]).
10+
*
11+
* A [Listener] is an entity that reacts to specific [Event]s happening within the system.
12+
* It has a [priority], an [owner],
13+
* and a flag indicating whether it should always listen to [Event]s,
14+
* even when the Object listening is [Muteable.isMuted] (e.g.: If it is a [Module] and not [Module.isEnabled]).
15+
*
16+
* The [Listener] class is not directly used to create listeners.
17+
* Instead, it serves as a base for the [SafeListener] and [UnsafeListener] classes,
18+
* which will trigger in different contexts (see [SafeListener] and [UnsafeListener]).
19+
*
20+
* The extending class needs to implement the [execute] method,
21+
* which defines the actions to be taken when the [Event] occurs.
22+
*
23+
* [Listener]s can be sorted based on their [priority],
24+
* if two [Listener]s have the same [priority], their order is determined by their [hashCode].
25+
*
26+
* @property priority The priority of the [Listener]. [Listener]s with higher [priority] are executed first.
27+
* @property owner The owner of the [Listener]. This is typically the object that created the [Listener].
28+
* @property alwaysListen If true, the [Listener] will always be triggered, even if the [owner] is not enabled.
29+
*/
530
abstract class Listener : Comparable<Listener> {
631
abstract val priority: Int
7-
abstract val owner: Any // ToDo: Evaluate if this is even needed
32+
abstract val owner: Any
833
abstract val alwaysListen: Boolean
934

35+
/**
36+
* Executes the actions defined by this listener when the event occurs.
37+
*
38+
* @param event The event that triggered this listener.
39+
*/
1040
abstract fun execute(event: Event)
1141

42+
/**
43+
* Compares this listener with another listener.
44+
* The comparison is based first on the priority, and then on the hash code of the listeners.
45+
*
46+
* @param other The other listener to compare with.
47+
* @return A negative integer, zero, or a positive integer as this listener is less than, equal to,
48+
* or greater than the specified listener.
49+
*/
1250
override fun compareTo(other: Listener) =
1351
compareBy<Listener> {
1452
it.priority

0 commit comments

Comments
 (0)