diff --git a/common/src/main/kotlin/com/lambda/config/Configuration.kt b/common/src/main/kotlin/com/lambda/config/Configuration.kt index 0b32e5e4e..5d4910888 100644 --- a/common/src/main/kotlin/com/lambda/config/Configuration.kt +++ b/common/src/main/kotlin/com/lambda/config/Configuration.kt @@ -24,7 +24,7 @@ import com.lambda.Lambda.LOG import com.lambda.Lambda.gson import com.lambda.config.configurations.ModuleConfig import com.lambda.event.events.ClientEvent -import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener +import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe import com.lambda.threading.runIO import com.lambda.util.Communication.info import com.lambda.util.Communication.logError @@ -57,9 +57,9 @@ abstract class Configuration : Jsonable { get() = File("${primary.parent}/${primary.nameWithoutExtension}-backup.${primary.extension}") init { - unsafeListener { tryLoad() } + listenUnsafe { tryLoad() } - unsafeListener(Int.MIN_VALUE) { trySave() } + listenUnsafe(Int.MIN_VALUE) { trySave() } register() } diff --git a/common/src/main/kotlin/com/lambda/core/PingManager.kt b/common/src/main/kotlin/com/lambda/core/PingManager.kt index e1c25d976..6c8d9bd0b 100644 --- a/common/src/main/kotlin/com/lambda/core/PingManager.kt +++ b/common/src/main/kotlin/com/lambda/core/PingManager.kt @@ -19,7 +19,7 @@ package com.lambda.core import com.lambda.event.events.PacketEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.util.collections.LimitedOrderedSet import net.minecraft.network.packet.c2s.query.QueryPingC2SPacket import net.minecraft.network.packet.s2c.query.PingResultS2CPacket @@ -33,12 +33,12 @@ object PingManager : Loadable { get() = pings.lastOrNull() ?: 0 init { - listener { + listen { connection.sendPacket(QueryPingC2SPacket(Util.getMeasuringTimeMs())) } - listener { event -> - if (event.packet !is PingResultS2CPacket) return@listener + listen { event -> + if (event.packet !is PingResultS2CPacket) return@listen pings.add(Util.getMeasuringTimeMs() - event.packet.startTime) } diff --git a/common/src/main/kotlin/com/lambda/event/EventFlow.kt b/common/src/main/kotlin/com/lambda/event/EventFlow.kt index 2017448d1..0b66b1478 100644 --- a/common/src/main/kotlin/com/lambda/event/EventFlow.kt +++ b/common/src/main/kotlin/com/lambda/event/EventFlow.kt @@ -66,7 +66,7 @@ object EventFlow { * the oldest event will be dropped to accommodate a new event. */ val concurrentFlow = MutableSharedFlow( - extraBufferCapacity = 1000, + extraBufferCapacity = 10000, onBufferOverflow = BufferOverflow.DROP_OLDEST ) diff --git a/common/src/main/kotlin/com/lambda/event/listener/SafeListener.kt b/common/src/main/kotlin/com/lambda/event/listener/SafeListener.kt index 2c537403e..49611d4cb 100644 --- a/common/src/main/kotlin/com/lambda/event/listener/SafeListener.kt +++ b/common/src/main/kotlin/com/lambda/event/listener/SafeListener.kt @@ -26,6 +26,8 @@ import com.lambda.threading.runConcurrent import com.lambda.threading.runSafe import com.lambda.util.Pointer import com.lambda.util.selfReference +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers import kotlin.properties.ReadOnlyProperty import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty @@ -99,11 +101,11 @@ class SafeListener( * * Usage: * ```kotlin - * listener { event -> + * listen { event -> * player.sendMessage("Event received: $event") * } * - * listener(priority = 1) { event -> + * listen(priority = 1) { event -> * player.sendMessage("Event received before the previous listener: $event") * } * ``` @@ -114,18 +116,65 @@ class SafeListener( * @param function The function to be executed when the event is posted. This function should take a SafeContext and an event of type T as parameters. * @return The newly created and registered [SafeListener]. */ - inline fun Any.listener( + inline fun Any.listen( priority: Int = 0, alwaysListen: Boolean = false, noinline function: SafeContext.(T) -> Unit = {}, ): SafeListener { - val listener = SafeListener(priority, this, alwaysListen) { event -> function(event) } + val listener = SafeListener(priority, this, alwaysListen) { event -> + function(event) + } EventFlow.syncListeners.subscribe(listener) return listener } + /** + * Registers a new [SafeListener] for a generic [Event] type [T] within the context of a [Task]. + * The [function] is executed on the same thread where the [Event] was dispatched. + * The [function] will only be executed when the context satisfies certain safety conditions. + * These conditions are met when none of the following [SafeContext] properties are null: + * - [SafeContext.world] + * - [SafeContext.player] + * - [SafeContext.interaction] + * - [SafeContext.connection] + * + * Usage: + * ```kotlin + * myTask.listen { event -> + * player.sendMessage("Event received: $event") + * } + * + * myTask.listen(priority = 1) { event -> + * player.sendMessage("Event received before the previous listener: $event") + * } + * ``` + * + * @param T The type of the event to listen for. + * This should be a subclass of Event. + * @param priority The priority of the listener. + * Listeners with higher priority will be executed first. + * The Default value is 0. + * @param alwaysListen If true, the listener will be executed even if it is muted. The Default value is false. + * @param function The function to be executed when the event is posted. + * This function should take a SafeContext and an event of type T as parameters. + * @return The newly created and registered [SafeListener]. + */ + inline fun Task<*>.listen( + priority: Int = 0, + alwaysListen: Boolean = false, + noinline function: SafeContext.(T) -> Unit = {}, + ): SafeListener { + val listener = SafeListener(priority, this, alwaysListen) { event -> + function(event) // ToDo: run function always on game thread + } + + syncListeners.subscribe(listener) + + return listener + } + /** * This function registers a new [SafeListener] for a generic [Event] type [T]. * The [transform] is executed on the same thread where the [Event] was dispatched. @@ -142,7 +191,7 @@ class SafeListener( * * Usage: * ```kotlin - * private val event by listenNext { event -> + * private val event by listenOnce { event -> * player.sendMessage("Event received only once: $event") * // event is stored in the value * // event is unsubscribed after execution @@ -181,51 +230,6 @@ class SafeListener( return pointer } - /** - * Registers a new [SafeListener] for a generic [Event] type [T] within the context of a [Task]. - * The [function] is executed on the same thread where the [Event] was dispatched. - * The [function] will only be executed when the context satisfies certain safety conditions. - * These conditions are met when none of the following [SafeContext] properties are null: - * - [SafeContext.world] - * - [SafeContext.player] - * - [SafeContext.interaction] - * - [SafeContext.connection] - * - * Usage: - * ```kotlin - * myTask.listener { event -> - * player.sendMessage("Event received: $event") - * } - * - * myTask.listener(priority = 1) { event -> - * player.sendMessage("Event received before the previous listener: $event") - * } - * ``` - * - * @param T The type of the event to listen for. - * This should be a subclass of Event. - * @param priority The priority of the listener. - * Listeners with higher priority will be executed first. - * The Default value is 0. - * @param alwaysListen If true, the listener will be executed even if it is muted. The Default value is false. - * @param function The function to be executed when the event is posted. - * This function should take a SafeContext and an event of type T as parameters. - * @return The newly created and registered [SafeListener]. - */ - inline fun Task<*>.listener( - priority: Int = 0, - alwaysListen: Boolean = false, - noinline function: SafeContext.(T) -> Unit = {}, - ): SafeListener { - val listener = SafeListener(priority, this, alwaysListen) { event -> - function(event) // ToDo: run function always on game thread - } - - syncListeners.subscribe(listener) - - return listener - } - /** * Registers a new [SafeListener] for a generic [Event] type [T]. * The [function] is executed on a new thread running asynchronously to the game thread. @@ -236,12 +240,12 @@ class SafeListener( * * Usage: * ```kotlin - * concurrentListener { event -> + * listenConcurrently { event -> * println("Concurrent event received: $event") * // no safe access to player or world * } * - * concurrentListener(priority = 1) { event -> + * listenConcurrently(priority = 1) { event -> * println("Concurrent event received before the previous listener: $event") * } * ``` @@ -251,13 +255,14 @@ class SafeListener( * @param function The function to be executed when the event is posted. This function should take a SafeContext and an event of type T as parameters. * @return The newly created and registered [SafeListener]. */ - inline fun Any.concurrentListener( + inline fun Any.listenConcurrently( priority: Int = 0, alwaysListen: Boolean = false, + scheduler: CoroutineDispatcher = Dispatchers.Default, noinline function: suspend SafeContext.(T) -> Unit = {}, ): SafeListener { val listener = SafeListener(priority, this, alwaysListen) { event -> - runConcurrent { + runConcurrent(scheduler) { function(event) } } diff --git a/common/src/main/kotlin/com/lambda/event/listener/UnsafeListener.kt b/common/src/main/kotlin/com/lambda/event/listener/UnsafeListener.kt index 170c8f093..221617062 100644 --- a/common/src/main/kotlin/com/lambda/event/listener/UnsafeListener.kt +++ b/common/src/main/kotlin/com/lambda/event/listener/UnsafeListener.kt @@ -81,16 +81,16 @@ class UnsafeListener( * The [function] is executed on the same thread where the [Event] was dispatched. * The execution of the [function] is independent of the safety conditions of the context. * Use this function when you need to listen to an [Event] in a context that is not in-game. - * For only in-game related contexts, use the [SafeListener.listener] function instead. + * For only in-game related contexts, use the [SafeListener.listen] function instead. * * Usage: * ```kotlin - * unsafeListener { event -> + * listenUnsafe { event -> * println("Unsafe event received: $event") * // no safe access to player or world * } * - * unsafeListener(priority = 1) { event -> + * listenUnsafe(priority = 1) { event -> * println("Unsafe event received before the previous listener: $event") * } * ``` @@ -101,7 +101,7 @@ class UnsafeListener( * @param function The function to be executed when the event is posted. This function should take an event of type T as a parameter. * @return The newly created and registered [UnsafeListener]. */ - inline fun Any.unsafeListener( + inline fun Any.listenUnsafe( priority: Int = 0, alwaysListen: Boolean = false, noinline function: (T) -> Unit = {}, @@ -123,7 +123,7 @@ class UnsafeListener( * * Usage: * ```kotlin - * private val event by unsafeListenOnce { event -> + * private val event by listenOnceUnsafe { event -> * println("Unsafe event received only once: $event") * // no safe access to player or world * // event is stored in the value @@ -139,7 +139,7 @@ class UnsafeListener( * @param transform The function used to transform the event into a value. * @return The newly created and registered [UnsafeListener]. */ - inline fun Any.unsafeListenOnce( + inline fun Any.listenOnceUnsafe( priority: Int = 0, alwaysListen: Boolean = false, noinline transform: (T) -> E? = { null }, @@ -148,7 +148,7 @@ class UnsafeListener( val pointer = Pointer() val destroyable by selfReference> { - UnsafeListener(priority, this@unsafeListenOnce, alwaysListen) { event -> + UnsafeListener(priority, this@listenOnceUnsafe, alwaysListen) { event -> pointer.value = transform(event) if (predicate(event) && @@ -169,19 +169,19 @@ class UnsafeListener( * Registers a new [UnsafeListener] for a generic [Event] type [T]. * The [function] is executed on a new thread running asynchronously to the game thread. * This function should only be used when the [function] performs read actions on the game data. - * For only in-game related contexts, use the [SafeListener.concurrentListener] function instead. + * For only in-game related contexts, use the [SafeListener.listenConcurrently] function instead. * * Caution: Using this function to write to the game data can lead to race conditions. Therefore, it is recommended * to use this function only for read operations to avoid potential concurrency issues. * * Usage: * ```kotlin - * concurrentListener { event -> + * listenUnsafeConcurrently { event -> * println("Concurrent event received: $event") * // no safe access to player or world * } * - * concurrentListener(priority = 1) { event -> + * listenUnsafeConcurrently(priority = 1) { event -> * println("Concurrent event received before the previous listener: $event") * } * ``` @@ -191,12 +191,14 @@ class UnsafeListener( * @param function The function to be executed when the event is posted. This function should take a SafeContext and an event of type T as parameters. * @return The newly created and registered [UnsafeListener]. */ - inline fun Any.unsafeConcurrentListener( + inline fun Any.listenUnsafeConcurrently( priority: Int = 0, alwaysListen: Boolean = false, noinline function: (T) -> Unit = {}, ): UnsafeListener { - val listener = UnsafeListener(priority, this, alwaysListen) { event -> function(event) } + val listener = UnsafeListener(priority, this, alwaysListen) { event -> + function(event) + } EventFlow.concurrentListeners.subscribe(listener) diff --git a/common/src/main/kotlin/com/lambda/graphics/RenderMain.kt b/common/src/main/kotlin/com/lambda/graphics/RenderMain.kt index aa37c6214..e1bce2df2 100644 --- a/common/src/main/kotlin/com/lambda/graphics/RenderMain.kt +++ b/common/src/main/kotlin/com/lambda/graphics/RenderMain.kt @@ -21,7 +21,7 @@ import com.lambda.Lambda.mc import com.lambda.event.EventFlow.post import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.animation.Animation.Companion.exp import com.lambda.graphics.animation.AnimationTicker import com.lambda.graphics.buffer.FrameBuffer @@ -46,7 +46,7 @@ object RenderMain { private val showHud get() = mc.currentScreen == null || LambdaHudGui.isOpen private val hudAnimation0 = with(AnimationTicker()) { - listener { + listen { tick() } diff --git a/common/src/main/kotlin/com/lambda/graphics/renderer/esp/ChunkedESP.kt b/common/src/main/kotlin/com/lambda/graphics/renderer/esp/ChunkedESP.kt index d3c0d232a..6210c599d 100644 --- a/common/src/main/kotlin/com/lambda/graphics/renderer/esp/ChunkedESP.kt +++ b/common/src/main/kotlin/com/lambda/graphics/renderer/esp/ChunkedESP.kt @@ -20,8 +20,8 @@ package com.lambda.graphics.renderer.esp import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent import com.lambda.event.events.WorldEvent -import com.lambda.event.listener.SafeListener.Companion.concurrentListener -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listenConcurrently +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.impl.ESPRenderer import com.lambda.graphics.renderer.esp.impl.StaticESPRenderer import com.lambda.module.modules.client.RenderSettings @@ -53,19 +53,19 @@ class ChunkedESP private constructor( } init { - concurrentListener { event -> + listenConcurrently { event -> world.getWorldChunk(event.pos).renderer.notifyChunks() } - concurrentListener { event -> + listenConcurrently { event -> event.chunk.renderer.notifyChunks() } - concurrentListener { event -> + listenConcurrently { event -> rendererMap.remove(event.chunk.pos.toLong())?.notifyChunks() } - owner.concurrentListener { + owner.listenConcurrently { if (++ticks % RenderSettings.updateFrequency == 0) { val polls = minOf(RenderSettings.rebuildsPerTick, rebuildQueue.size) @@ -76,8 +76,8 @@ class ChunkedESP private constructor( } } - owner.listener { - if (uploadQueue.isEmpty()) return@listener + owner.listen { + if (uploadQueue.isEmpty()) return@listen val polls = minOf(RenderSettings.uploadsPerTick, uploadQueue.size) @@ -86,7 +86,7 @@ class ChunkedESP private constructor( } } - owner.listener { + owner.listen { rendererMap.values.forEach { it.renderer?.render() } diff --git a/common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/DynamicESP.kt b/common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/DynamicESP.kt index 2a0e837ad..32ac305fa 100644 --- a/common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/DynamicESP.kt +++ b/common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/DynamicESP.kt @@ -20,12 +20,12 @@ package com.lambda.graphics.renderer.esp.global import com.lambda.event.EventFlow.post import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.impl.DynamicESPRenderer object DynamicESP : DynamicESPRenderer() { init { - listener { + listen { clear() RenderEvent.DynamicESP().post() upload() diff --git a/common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/StaticESP.kt b/common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/StaticESP.kt index 8f4ce984b..ce00e73c3 100644 --- a/common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/StaticESP.kt +++ b/common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/StaticESP.kt @@ -20,12 +20,12 @@ package com.lambda.graphics.renderer.esp.global import com.lambda.event.EventFlow.post import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.impl.StaticESPRenderer object StaticESP : StaticESPRenderer(false) { init { - listener { + listen { clear() RenderEvent.StaticESP().post() upload() diff --git a/common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt b/common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt index e3119d1d5..e8f71a52d 100644 --- a/common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt +++ b/common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt @@ -21,7 +21,7 @@ import com.lambda.Lambda.mc import com.lambda.event.Muteable import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.animation.AnimationTicker import com.lambda.gui.api.component.core.IComponent import com.lambda.gui.impl.AbstractClickGui @@ -51,12 +51,12 @@ abstract class LambdaGui( val animation = AnimationTicker() init { - listener { event -> + listen { event -> screenSize = event.screenSize onEvent(GuiEvent.Render()) } - listener { + listen { animation.tick() onEvent(GuiEvent.Tick()) } diff --git a/common/src/main/kotlin/com/lambda/interaction/RotationManager.kt b/common/src/main/kotlin/com/lambda/interaction/RotationManager.kt index 6dae4c483..f3c43d8ca 100644 --- a/common/src/main/kotlin/com/lambda/interaction/RotationManager.kt +++ b/common/src/main/kotlin/com/lambda/interaction/RotationManager.kt @@ -23,8 +23,8 @@ import com.lambda.context.SafeContext import com.lambda.core.Loadable import com.lambda.event.EventFlow.post import com.lambda.event.events.* -import com.lambda.event.listener.SafeListener.Companion.listener -import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener +import com.lambda.event.listener.SafeListener.Companion.listen +import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe import com.lambda.interaction.rotation.Rotation import com.lambda.interaction.rotation.Rotation.Companion.angleDifference import com.lambda.interaction.rotation.Rotation.Companion.fixSensitivity @@ -60,7 +60,7 @@ object RotationManager : Loadable { ) { var lastCtx: RotationContext? = null - this.listener(priority, alwaysListen) { event -> + this.listen(priority, alwaysListen) { event -> val rotationContext = onUpdate(event.context) rotationContext?.let { @@ -70,7 +70,7 @@ object RotationManager : Loadable { lastCtx = rotationContext } - this.listener { event -> + this.listen { event -> if (event.context == lastCtx && event.context.isValid) { onReceive() } @@ -89,16 +89,16 @@ object RotationManager : Loadable { } init { - listener { event -> + listen { event -> val packet = event.packet - if (packet !is PlayerPositionLookS2CPacket) return@listener + if (packet !is PlayerPositionLookS2CPacket) return@listen runGameScheduled { reset(Rotation(packet.yaw, packet.pitch)) } } - unsafeListener { + listenUnsafe { reset(Rotation.ZERO) } } diff --git a/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt b/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt index 36eee4183..12d98ef08 100644 --- a/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt +++ b/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt @@ -20,7 +20,7 @@ package com.lambda.interaction.material import com.lambda.core.Loadable import com.lambda.event.events.PlayerEvent import com.lambda.event.events.ScreenHandlerEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.material.StackSelection.Companion.select import com.lambda.interaction.material.container.* import com.lambda.module.modules.client.TaskFlow @@ -51,18 +51,18 @@ object ContainerManager : Loadable { private var lastInteractedBlockEntity: BlockEntity? = null init { - listener { + listen { lastInteractedBlockEntity = it.blockHitResult.blockPos.blockEntity(world) } - listener { event -> - if (event.screenHandler !is GenericContainerScreenHandler) return@listener + listen { event -> + if (event.screenHandler !is GenericContainerScreenHandler) return@listen val handler = event.screenHandler when (val block = lastInteractedBlockEntity) { is EnderChestBlockEntity -> { - if (handler.type != ScreenHandlerType.GENERIC_9X3) return@listener + if (handler.type != ScreenHandlerType.GENERIC_9X3) return@listen this@ContainerManager.info("Updating EnderChestContainer") EnderChestContainer.update(handler.containerStacks) @@ -70,7 +70,7 @@ object ContainerManager : Loadable { is ChestBlockEntity -> { // ToDo: Handle double chests and single chests - if (handler.type != ScreenHandlerType.GENERIC_9X6) return@listener + if (handler.type != ScreenHandlerType.GENERIC_9X6) return@listen val stacks = handler.containerStacks this@ContainerManager.info("Updating ChestContainer") diff --git a/common/src/main/kotlin/com/lambda/module/HudModule.kt b/common/src/main/kotlin/com/lambda/module/HudModule.kt index a881753c2..c9c68db0d 100644 --- a/common/src/main/kotlin/com/lambda/module/HudModule.kt +++ b/common/src/main/kotlin/com/lambda/module/HudModule.kt @@ -19,9 +19,8 @@ package com.lambda.module import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.animation.AnimationTicker -import com.lambda.gui.api.GuiEvent import com.lambda.gui.api.RenderLayer import com.lambda.gui.api.component.core.DockingRect import com.lambda.module.tag.ModuleTag @@ -84,7 +83,7 @@ abstract class HudModule( renderCallables.add(block) init { - listener { event -> + listen { event -> rectHandler.screenSize = event.screenSize renderCallables.forEach { function -> @@ -94,7 +93,7 @@ abstract class HudModule( renderer.render() } - listener { + listen { animation.tick() } } diff --git a/common/src/main/kotlin/com/lambda/module/Module.kt b/common/src/main/kotlin/com/lambda/module/Module.kt index dc9987f37..76680ba8e 100644 --- a/common/src/main/kotlin/com/lambda/module/Module.kt +++ b/common/src/main/kotlin/com/lambda/module/Module.kt @@ -29,7 +29,7 @@ import com.lambda.event.Muteable import com.lambda.event.events.KeyboardEvent import com.lambda.event.listener.Listener import com.lambda.event.listener.SafeListener -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.event.listener.UnsafeListener import com.lambda.gui.impl.clickgui.buttons.ModuleButton import com.lambda.module.modules.client.ClickGui @@ -38,7 +38,6 @@ import com.lambda.sound.LambdaSound import com.lambda.sound.SoundManager.playSoundRandomly import com.lambda.util.KeyCode import com.lambda.util.Nameable -import net.minecraft.client.gui.screen.ChatScreen /** * A [Module] is a feature or tool for the utility mod. @@ -128,11 +127,11 @@ abstract class Module( val keybind by keybindSetting init { - listener(alwaysListen = true) { event -> - if (mc.options.commandKey.isPressed) return@listener - if (keybind == KeyCode.UNBOUND) return@listener - if (event.translated != keybind) return@listener - if (mc.currentScreen != null) return@listener + listen(alwaysListen = true) { event -> + if (mc.options.commandKey.isPressed) return@listen + if (keybind == KeyCode.UNBOUND) return@listen + if (event.translated != keybind) return@listen + if (mc.currentScreen != null) return@listen toggle() } diff --git a/common/src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt b/common/src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt index d515fa71a..6bfdbfa80 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt @@ -19,8 +19,8 @@ package com.lambda.module.modules.client import com.lambda.event.events.ClientEvent import com.lambda.event.events.KeyboardEvent -import com.lambda.event.listener.SafeListener.Companion.listener -import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener +import com.lambda.event.listener.SafeListener.Companion.listen +import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe import com.lambda.gui.impl.clickgui.LambdaClickGui import com.lambda.gui.impl.hudgui.LambdaHudGui import com.lambda.module.Module @@ -62,15 +62,15 @@ object ClickGui : Module( LambdaHudGui.close() } - listener(priority = Int.MAX_VALUE) { event -> - if (mc.options.commandKey.isPressed) return@listener - if (keybind == KeyCode.UNBOUND) return@listener - if (event.translated != keybind) return@listener + listen(priority = Int.MAX_VALUE) { event -> + if (mc.options.commandKey.isPressed) return@listen + if (keybind == KeyCode.UNBOUND) return@listen + if (event.translated != keybind) return@listen // ToDo: Exception for ui text input toggle() } - unsafeListener { + listenUnsafe { disable() } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/client/DiscordRPC.kt b/common/src/main/kotlin/com/lambda/module/modules/client/DiscordRPC.kt index 12650071c..1a5133070 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/client/DiscordRPC.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/client/DiscordRPC.kt @@ -22,7 +22,7 @@ import com.lambda.Lambda.LOG import com.lambda.Lambda.mc import com.lambda.event.EventFlow import com.lambda.event.events.ConnectionEvent -import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener +import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe import com.lambda.http.api.rpc.v1.endpoints.* import com.lambda.http.api.rpc.v1.models.Authentication import com.lambda.http.api.rpc.v1.models.Party @@ -96,19 +96,19 @@ object DiscordRPC : Module( get() = currentParty?.players?.any { it.uuid == this@isInParty.uuid } init { - unsafeListener { + listenUnsafe { connectionTime = System.currentTimeMillis() serverId = it.serverId } - unsafeListener { + listenUnsafe { if (it.secretKey.isDestroyed) - return@unsafeListener logError("Error during the login process", "The client secret key was destroyed by another listener") + return@listenUnsafe logError("Error during the login process", "The client secret key was destroyed by another listener") keyEvent = it } - unsafeListener { connect() } + listenUnsafe { connect() } // TODO: Exponential backoff up to 25 seconds onEnable { connect() } diff --git a/common/src/main/kotlin/com/lambda/module/modules/client/GuiSettings.kt b/common/src/main/kotlin/com/lambda/module/modules/client/GuiSettings.kt index 622c3eb8b..8233109fc 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/client/GuiSettings.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/client/GuiSettings.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.client import com.lambda.event.events.ConnectionEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener +import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe import com.lambda.graphics.animation.Animation.Companion.exp import com.lambda.graphics.animation.AnimationTicker import com.lambda.gui.impl.clickgui.LambdaClickGui @@ -69,12 +69,12 @@ object GuiSettings : Module( } private val animation = with(AnimationTicker()) { - unsafeListener(alwaysListen = true) { + listenUnsafe(alwaysListen = true) { tick() } exp({ targetScale }, 0.5).apply { - unsafeListener(alwaysListen = true) { + listenUnsafe(alwaysListen = true) { setValue(targetScale) } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/client/LambdaMoji.kt b/common/src/main/kotlin/com/lambda/module/modules/client/LambdaMoji.kt index 32f5dd38f..23d5c8212 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/client/LambdaMoji.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/client/LambdaMoji.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.client import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.gui.api.RenderLayer import com.lambda.module.Module import com.lambda.module.tag.ModuleTag @@ -37,7 +37,7 @@ object LambdaMoji : Module( private val renderQueue = hashMapOf, List>() init { - listener { + listen { var index = 0 renderQueue.forEach { (emojis, positions) -> emojis.forEachIndexed { emojiIndex, emoji -> @@ -54,7 +54,7 @@ object LambdaMoji : Module( } } - listener { + listen { renderer.render() } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt b/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt index 311aafb3d..fcaf6308c 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.combat import com.lambda.context.SafeContext import com.lambda.event.events.PlayerEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.rotation.Rotation import com.lambda.interaction.rotation.Rotation.Companion.rotationTo import com.lambda.module.Module @@ -47,7 +47,7 @@ object Criticals : Module( } init { - listener { + listen { when (mode) { Mode.Grim -> { if (player.isOnGround) posPacket(0.00000001, rotation = player.rotation) diff --git a/common/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt b/common/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt index 67a7adc28..76725d472 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt @@ -20,7 +20,7 @@ package com.lambda.module.modules.combat import com.lambda.config.groups.InteractionSettings import com.lambda.config.groups.RotationSettings import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.concurrentListener +import com.lambda.event.listener.SafeListener.Companion.listenConcurrently import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import net.minecraft.util.Hand @@ -65,7 +65,7 @@ object CrystalAura : Module( } init { - concurrentListener {} + listenConcurrently {} /*listener { event -> event.lookAtEntity(rotation, interac, getClosestEntity(player.eyePos, placeRange) ?: return@listener) diff --git a/common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt b/common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt index d383541b4..b09d0948f 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt @@ -24,7 +24,7 @@ import com.lambda.context.SafeContext import com.lambda.event.events.PacketEvent import com.lambda.event.events.PlayerPacketEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.RotationManager import com.lambda.interaction.RotationManager.requestRotation import com.lambda.interaction.rotation.Rotation @@ -123,13 +123,13 @@ object KillAura : Module( } ) - listener(Int.MIN_VALUE) { event -> + listen(Int.MIN_VALUE) { event -> prevY = lastY lastY = event.position.y lastOnGround = event.onGround } - listener { + listen { target = targeting.target() if (!timerSync) attackTicks++ @@ -148,11 +148,11 @@ object KillAura : Module( } } - listener { event -> + listen { event -> if (event.packet !is HandSwingC2SPacket && event.packet !is UpdateSelectedSlotC2SPacket && event.packet !is PlayerInteractEntityC2SPacket - ) return@listener + ) return@listen attackTicks = 0 } diff --git a/common/src/main/kotlin/com/lambda/module/modules/debug/BaritoneTest.kt b/common/src/main/kotlin/com/lambda/module/modules/debug/BaritoneTest.kt index 2d2624025..87696ef9d 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/debug/BaritoneTest.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/debug/BaritoneTest.kt @@ -20,7 +20,7 @@ package com.lambda.module.modules.debug import baritone.api.BaritoneAPI import baritone.api.pathing.goals.GoalXZ import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag @@ -30,7 +30,7 @@ object BaritoneTest : Module( defaultTags = setOf(ModuleTag.DEBUG) ) { init { - listener { + listen { BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(0, 0)) } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/debug/BlockTest.kt b/common/src/main/kotlin/com/lambda/module/modules/debug/BlockTest.kt index 9afb9a153..49f56c2ed 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/debug/BlockTest.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/debug/BlockTest.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.debug import com.lambda.event.events.RenderEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.builders.build import com.lambda.module.Module import com.lambda.module.tag.ModuleTag @@ -49,7 +49,7 @@ object BlockTest : Module( private val outlineColor = Color(100, 150, 255, 51) init { - listener { + listen { blockSearch(range, step) { _, state -> state.isOf(Blocks.DIAMOND_BLOCK) }.forEach { (pos, state) -> diff --git a/common/src/main/kotlin/com/lambda/module/modules/debug/ContainerTest.kt b/common/src/main/kotlin/com/lambda/module/modules/debug/ContainerTest.kt index 8ee9068e8..c541a6fdb 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/debug/ContainerTest.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/debug/ContainerTest.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.debug import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.material.StackSelection.Companion.select import com.lambda.module.Module import com.lambda.module.tag.ModuleTag @@ -31,7 +31,7 @@ object ContainerTest : Module( defaultTags = setOf(ModuleTag.DEBUG) ) { init { - listener { + listen { // info(task.info) } diff --git a/common/src/main/kotlin/com/lambda/module/modules/debug/InventoryDebug.kt b/common/src/main/kotlin/com/lambda/module/modules/debug/InventoryDebug.kt index 0ac0c82cb..034e6380a 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/debug/InventoryDebug.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/debug/InventoryDebug.kt @@ -20,7 +20,7 @@ package com.lambda.module.modules.debug import com.lambda.Lambda.LOG import com.lambda.event.events.PacketEvent import com.lambda.event.events.ScreenHandlerEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.util.Communication.info @@ -35,19 +35,19 @@ object InventoryDebug : Module( defaultTags = setOf(ModuleTag.DEBUG) ) { init { - listener { + listen { info("Opened screen handler: ${it.screenHandler::class.simpleName}") } - listener { + listen { info("Closed screen handler: ${it.screenHandler::class.simpleName}") } - listener { + listen { info("Updated screen handler: ${it.revision}, ${it.stacks}, ${it.cursorStack}") } - listener { + listen { when (val packet = it.packet) { is UpdateSelectedSlotS2CPacket, is InventoryS2CPacket -> { this@InventoryDebug.info(packet.dynamicString()) @@ -55,7 +55,7 @@ object InventoryDebug : Module( } } - listener { + listen { when (it.packet) { is SlotChangedStateC2SPacket, is ClickSlotC2SPacket, diff --git a/common/src/main/kotlin/com/lambda/module/modules/debug/RenderTest.kt b/common/src/main/kotlin/com/lambda/module/modules/debug/RenderTest.kt index 2beae6ce6..7a4b168f3 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/debug/RenderTest.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/debug/RenderTest.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.debug import com.lambda.event.events.RenderEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.DynamicAABB.Companion.dynamicBox import com.lambda.graphics.renderer.esp.builders.build import com.lambda.module.Module @@ -45,14 +45,14 @@ object RenderTest : Module( private val filledColor = outlineColor.setAlpha(0.2) init { - listener { + listen { entitySearch(8.0) .forEach { entity -> it.renderer.build(entity.dynamicBox, filledColor, outlineColor) } } - listener { + listen { it.renderer.build(Box.of(player.pos, 0.3, 0.3, 0.3), filledColor, outlineColor) } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt index 60e72dbf7..bd70f3f29 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt @@ -22,7 +22,7 @@ import com.lambda.event.events.ConnectionEvent import com.lambda.event.events.PacketEvent import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.DynamicAABB import com.lambda.graphics.renderer.esp.builders.build import com.lambda.module.Module @@ -92,7 +92,7 @@ object BackTrack : Module( } init { - listener { + listen { val prevTarget = target target = if (KillAura.isDisabled) null else KillAura.target val currentTarget = target @@ -101,7 +101,7 @@ object BackTrack : Module( poolPackets(true) targetPos = null box.reset() - return@listener + return@listen } val pos = targetPos ?: currentTarget.pos @@ -111,8 +111,8 @@ object BackTrack : Module( poolPackets() } - listener { - val target = target ?: return@listener + listen { + val target = target ?: return@listen val c1 = GuiSettings.primaryColor val c2 = Color.RED @@ -122,14 +122,14 @@ object BackTrack : Module( it.renderer.build(box, c.multAlpha(0.3), c.multAlpha(0.8)) } - listener { event -> - if (!outbound || target == null) return@listener + listen { event -> + if (!outbound || target == null) return@listen sendPool.add(event.packet to currentTime) event.cancel() } - listener { event -> - val target = target ?: return@listener + listen { event -> + val target = target ?: return@listen val packet = event.packet @@ -155,7 +155,7 @@ object BackTrack : Module( is PlaySoundS2CPacket, is PlaySoundFromEntityS2CPacket, is StopSoundS2CPacket, /*is EntityStatusS2CPacket,*/ is EntityStatusEffectS2CPacket, is EntityAnimationS2CPacket, is ParticleS2CPacket, is WorldTimeUpdateS2CPacket, is WorldEventS2CPacket -> { - return@listener + return@listen } } @@ -163,7 +163,7 @@ object BackTrack : Module( event.cancel() } - listener { + listen { receivePool.clear() sendPool.clear() } diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/Blink.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/Blink.kt index 067a4cb22..1b0eed92b 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/Blink.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/Blink.kt @@ -20,7 +20,7 @@ package com.lambda.module.modules.movement import com.lambda.context.SafeContext import com.lambda.event.events.PacketEvent import com.lambda.event.events.RenderEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.DynamicAABB import com.lambda.graphics.renderer.esp.builders.build import com.lambda.module.Module @@ -58,47 +58,47 @@ object Blink : Module( private var lastBox = Box(BlockPos.ORIGIN) init { - listener { + listen { val time = System.currentTimeMillis() - if (isActive && time - lastUpdate < delay) return@listener + if (isActive && time - lastUpdate < delay) return@listen lastUpdate = time poolPackets() } - listener { event -> + listen { event -> val color = GuiSettings.primaryColor event.renderer.build(box.update(lastBox), color.setAlpha(0.3), color) } - listener { event -> - if (!isActive) return@listener + listen { event -> + if (!isActive) return@listen packetPool.add(event.packet) event.cancel() - return@listener + return@listen } - listener { event -> + listen { event -> val packet = event.packet - if (packet !is PlayerMoveC2SPacket) return@listener + if (packet !is PlayerMoveC2SPacket) return@listen val vec = Vec3d(packet.getX(0.0), packet.getY(0.0), packet.getZ(0.0)) - if (vec == Vec3d.ZERO) return@listener + if (vec == Vec3d.ZERO) return@listen lastBox = player.boundingBox.offset(vec - player.pos) } - listener { event -> - if (!isActive || !shiftVelocity) return@listener + listen { event -> + if (!isActive || !shiftVelocity) return@listen - if (event.packet !is EntityVelocityUpdateS2CPacket) return@listener - if (event.packet.id != player.id) return@listener + if (event.packet !is EntityVelocityUpdateS2CPacket) return@listen + if (event.packet.id != player.id) return@listen lastVelocity = event.packet event.cancel() - return@listener + return@listen } onDisable { diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt index 7f569dba3..e67f1b401 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.movement import com.lambda.event.events.ClientEvent import com.lambda.event.events.MovementEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.threading.runSafe @@ -45,15 +45,15 @@ object ElytraFly : Module( val doBoost: Boolean get() = isEnabled && rocketBoost init { - listener { + listen { if (playerBoost && player.isFallFlying && !player.isUsingItem) { addSpeed(playerSpeed) } } - listener { event -> - if (!mute) return@listener - if (event.sound.id != SoundEvents.ITEM_ELYTRA_FLYING.id) return@listener + listen { event -> + if (!mute) return@listen + if (event.sound.id != SoundEvents.ITEM_ELYTRA_FLYING.id) return@listen event.cancel() } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/EntityControl.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/EntityControl.kt index 5569a47b1..d585730af 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/EntityControl.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/EntityControl.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.movement import com.lambda.event.events.PacketEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.util.world.fastEntitySearch @@ -36,7 +36,7 @@ object EntityControl : Module( private val saddledHorses = mutableSetOf() init { - listener { + listen { fastEntitySearch(8.0) .forEach { if (!it.isSaddled) saddledHorses.add(it) @@ -44,13 +44,13 @@ object EntityControl : Module( } } - listener { event -> - if (!forceMount) return@listener - if (event.packet !is PlayerInteractEntityC2SPacket) return@listener - if (event.packet.type !is PlayerInteractEntityC2SPacket.InteractAtHandler) return@listener + listen { event -> + if (!forceMount) return@listen + if (event.packet !is PlayerInteractEntityC2SPacket) return@listen + if (event.packet.type !is PlayerInteractEntityC2SPacket.InteractAtHandler) return@listen - val entity = world.getEntityById(event.packet.entityId) ?: return@listener - if (entity !is AbstractHorseEntity) return@listener + val entity = world.getEntityById(event.packet.entityId) ?: return@listen + if (entity !is AbstractHorseEntity) return@listen event.cancel() } diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/Jesus.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/Jesus.kt index 55855284f..1d36a2b89 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/Jesus.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/Jesus.kt @@ -22,7 +22,7 @@ import com.lambda.event.events.MovementEvent import com.lambda.event.events.PlayerPacketEvent import com.lambda.event.events.TickEvent import com.lambda.event.events.WorldEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.util.Nameable @@ -62,11 +62,11 @@ object Jesus : Module( private var shouldWork = false init { - listener { event -> - if (!shouldWork || !waterAt(-0.0001)) return@listener + listen { event -> + if (!shouldWork || !waterAt(-0.0001)) return@listen event.onGround = false - if (!player.isOnGround) return@listener + if (!player.isOnGround) return@listen when (mode) { Mode.NCP -> { @@ -82,15 +82,15 @@ object Jesus : Module( } } - listener { - if (!shouldWork) return@listener + listen { + if (!shouldWork) return@listen goUp = waterAt(0.0001) val collidingWater = waterAt(-0.0001) when (mode) { Mode.NCP -> { - if (!collidingWater || !player.isOnGround) return@listener + if (!collidingWater || !player.isOnGround) return@listen setSpeed(Speed.NCP_BASE_SPEED * isInputting.toInt()) } @@ -107,7 +107,7 @@ object Jesus : Module( Mode.NCP_NEW -> { if (!collidingWater) { swimmingTicks = 0 - return@listener + return@listen } if (++swimmingTicks < 15) { @@ -115,7 +115,7 @@ object Jesus : Module( setSpeed(Speed.NCP_BASE_SPEED * isInputting.toInt()) } - return@listener + return@listen } swimmingTicks = 0 @@ -126,20 +126,20 @@ object Jesus : Module( } } - listener { event -> - if (!shouldWork || goUp || !mode.collision) return@listener + listen { event -> + if (!shouldWork || goUp || !mode.collision) return@listen if (event.state.block == Blocks.WATER) { event.shape = fullShape } } - listener { - if (!shouldWork || !goUp || mode == Mode.NCP_DOLPHIN) return@listener + listen { + if (!shouldWork || !goUp || mode == Mode.NCP_DOLPHIN) return@listen it.input.jumping = true } - listener { + listen { shouldWork = !player.abilities.flying && !player.isFallFlying && !player.input.sneaking } diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/NoFall.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/NoFall.kt index 5564b16f1..0b342a16b 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/NoFall.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/NoFall.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.movement import com.lambda.event.events.MovementEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.util.extension.component1 @@ -46,10 +46,10 @@ object NoFall : Module( } init { - listener { + listen { when (mode) { Mode.Grim -> { - if (player.fallDistance + player.motionY < 3.0) return@listener + if (player.fallDistance + player.motionY < 3.0) return@listen val (x, y, z) = player.pos connection.sendPacket(PlayerMoveC2SPacket.Full(x, y + 0.0000000001, z, 0.01f, 90f, false)) diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/RocketExtend.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/RocketExtend.kt index 64bfd28f6..c755dbf0a 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/RocketExtend.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/RocketExtend.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.movement import com.lambda.context.SafeContext import com.lambda.event.events.PacketEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.util.extension.filterPointer @@ -39,7 +39,7 @@ object RocketExtend : Module( private val keepAliveTime by setting("Keepalive Timeout", 45, 0..60, 1, unit = " s") init { - listener { event -> + listen { event -> if (event.packet is PlayerPositionLookS2CPacket) reset() if (event.packet is EntitiesDestroyS2CPacket) { @@ -50,17 +50,17 @@ object RocketExtend : Module( } } - listener { event -> - if (event.packet !is CommonPongC2SPacket) return@listener + listen { event -> + if (event.packet !is CommonPongC2SPacket) return@listen if (extendedRockets.isEmpty()) { lastPingTime = System.currentTimeMillis() - return@listener + return@listen } if (System.currentTimeMillis() - lastPingTime > keepAliveTime * 1000) { reset() - return@listener + return@listen } pingPacket = event.packet diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/SafeWalk.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/SafeWalk.kt index aa41488bb..f50ae4e68 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/SafeWalk.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/SafeWalk.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.movement import com.lambda.event.events.MovementEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import net.minecraft.entity.LivingEntity @@ -33,13 +33,13 @@ object SafeWalk : Module( private val stepHeight by setting("Step Height", 1.1, 0.0..4.0, 0.05, unit = " blocks") init { - listener { + listen { if (sneakOnLedge && player.isOnGround && player.isNearLedge(ledgeDistance, stepHeight)) { it.input.sneaking = true } } - listener { + listen { if (!sneakOnLedge) it.clip = true } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt index 505712202..20b7ab900 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt @@ -21,7 +21,7 @@ import com.lambda.config.groups.IRotationConfig import com.lambda.context.SafeContext import com.lambda.event.events.ClientEvent import com.lambda.event.events.MovementEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.RotationManager.requestRotation import com.lambda.interaction.rotation.Rotation import com.lambda.interaction.rotation.RotationContext @@ -97,10 +97,10 @@ object Speed : Module( } init { - listener { + listen { if (!shouldWork()) { reset() - return@listener + return@listen } when (mode) { @@ -109,22 +109,22 @@ object Speed : Module( } } - listener { + listen { lastDistance = player.moveDelta } - listener { - if (mode != Mode.NCP_STRAFE) return@listener - if (!shouldWork() || !isInputting) return@listener + listen { + if (mode != Mode.NCP_STRAFE) return@listen + if (!shouldWork() || !isInputting) return@listen it.speed = ncpTimerBoost } - listener { + listen { if (mode == Mode.NCP_STRAFE && shouldWork()) it.cancel() } - listener(Int.MIN_VALUE) { - if (mode != Mode.GRIM_STRAFE || !shouldWork()) return@listener + listen(Int.MIN_VALUE) { + if (mode != Mode.GRIM_STRAFE || !shouldWork()) return@listen // Delay jumping key state by 1 tick to let the rotation predict jump timing it.input.apply { diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/TargetStrafe.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/TargetStrafe.kt index 016435738..0ac488f05 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/TargetStrafe.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/TargetStrafe.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.movement import com.lambda.event.events.RotationEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.rotation.Rotation.Companion.rotationTo import com.lambda.module.Module import com.lambda.module.modules.combat.KillAura @@ -49,7 +49,7 @@ object TargetStrafe : Module( val isActive get() = isEnabled && KillAura.isEnabled && KillAura.target != null init { - listener { + listen { if (player.horizontalCollision) strafeDirection *= -1 if (KillAura.target == null) { @@ -58,7 +58,7 @@ object TargetStrafe : Module( } } - listener { event -> + listen { event -> KillAura.target?.let { target -> event.strafeYaw = player.eyePos.rotationTo(target.boundingBox.center).yaw diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/TickShift.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/TickShift.kt index 35aa4d27b..873d89616 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/TickShift.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/TickShift.kt @@ -21,7 +21,7 @@ import com.lambda.context.SafeContext import com.lambda.event.events.ClientEvent import com.lambda.event.events.PacketEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.modules.combat.KillAura import com.lambda.module.tag.ModuleTag @@ -64,7 +64,7 @@ object TickShift : Module( private var lastBoost = 0L init { - listener { + listen { if (Blink.isEnabled) { this@TickShift.info("TickShift is incompatible with blink") disable() @@ -83,8 +83,8 @@ object TickShift : Module( } } - listener { - if (it.packet !is PlayerMoveC2SPacket) return@listener + listen { + if (it.packet !is PlayerMoveC2SPacket) return@listen if (!strict) balance-- } @@ -101,33 +101,33 @@ object TickShift : Module( } } - listener { + listen { if (!isActive) { poolPackets() - return@listener + return@listen } it.speed = if (boost) boostAmount else slowdown } - listener { event -> - if (!isActive || !grim || event.isCanceled()) return@listener - if (event.packet !is CommonPongC2SPacket) return@listener + listen { event -> + if (!isActive || !grim || event.isCanceled()) return@listen + if (event.packet !is CommonPongC2SPacket) return@listen pingPool.add(event.packet) event.cancel() - return@listener + return@listen } - listener { event -> - if (!isActive || !grim || !shiftVelocity || event.isCanceled()) return@listener + listen { event -> + if (!isActive || !grim || !shiftVelocity || event.isCanceled()) return@listen - if (event.packet !is EntityVelocityUpdateS2CPacket) return@listener - if (event.packet.id != player.id) return@listener + if (event.packet !is EntityVelocityUpdateS2CPacket) return@listen + if (event.packet.id != player.id) return@listen lastVelocity = event.packet event.cancel() - return@listener + return@listen } onEnable { diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/Timer.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/Timer.kt index 9f14000ed..abbd113f1 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/Timer.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/Timer.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.movement import com.lambda.event.events.ClientEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag @@ -30,7 +30,7 @@ object Timer : Module( private val timer by setting("Timer", 1.0, 0.0..10.0, 0.01) init { - listener { + listen { it.speed = timer.coerceAtLeast(0.05) } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/network/PacketDelay.kt b/common/src/main/kotlin/com/lambda/module/modules/network/PacketDelay.kt index 8c00bcc59..bb2a8829f 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/network/PacketDelay.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/network/PacketDelay.kt @@ -20,7 +20,7 @@ package com.lambda.module.modules.network import com.lambda.context.SafeContext import com.lambda.event.events.PacketEvent import com.lambda.event.events.RenderEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.threading.runConcurrent @@ -51,14 +51,14 @@ object PacketDelay : Module( private var inboundLastUpdate = 0L init { - listener { - if (mode != Mode.STATIC) return@listener + listen { + if (mode != Mode.STATIC) return@listen flushPools(System.currentTimeMillis()) } - listener(Int.MIN_VALUE) { event -> - if (!packetScope.filter(event.packet)) return@listener + listen(Int.MIN_VALUE) { event -> + if (!packetScope.filter(event.packet)) return@listen when (mode) { Mode.STATIC -> { @@ -78,8 +78,8 @@ object PacketDelay : Module( } } - listener(Int.MIN_VALUE) { event -> - if (!packetScope.filter(event.packet)) return@listener + listen(Int.MIN_VALUE) { event -> + if (!packetScope.filter(event.packet)) return@listen when (mode) { Mode.STATIC -> { diff --git a/common/src/main/kotlin/com/lambda/module/modules/network/PacketLimiter.kt b/common/src/main/kotlin/com/lambda/module/modules/network/PacketLimiter.kt index 6d6f95e09..81210e87f 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/network/PacketLimiter.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/network/PacketLimiter.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.network import com.lambda.event.events.PacketEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.util.Communication.info @@ -60,11 +60,11 @@ object PacketLimiter : Module( packetQueue = LimitedDecayQueue(limit, interval) } - listener(Int.MAX_VALUE) { - if (it.packet::class.simpleName in ignorePackets) return@listener + listen(Int.MAX_VALUE) { + if (it.packet::class.simpleName in ignorePackets) return@listen // this@PacketLimiter.info("Packet sent: ${it.packet::class.simpleName} (${packetQueue.size} / $limit) ${Instant.now()}") - if (packetQueue.add(it)) return@listener + if (packetQueue.add(it)) return@listen it.cancel() this@PacketLimiter.info("Packet limit reached, dropping packet: ${it.packet::class.simpleName} (${packetQueue.size} / $limit)") diff --git a/common/src/main/kotlin/com/lambda/module/modules/network/PacketLogger.kt b/common/src/main/kotlin/com/lambda/module/modules/network/PacketLogger.kt index 9d1bd3849..36901a705 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/network/PacketLogger.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/network/PacketLogger.kt @@ -21,8 +21,8 @@ import com.lambda.Lambda import com.lambda.Lambda.mc import com.lambda.event.events.PacketEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.UnsafeListener.Companion.unsafeConcurrentListener -import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener +import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafeConcurrently +import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.threading.runIO @@ -155,45 +155,45 @@ object PacketLogger : Module( } } - unsafeListener { - if (!logTicks) return@unsafeListener + listenUnsafe { + if (!logTicks) return@listenUnsafe storageFlow.tryEmit("Started tick at ${getTime(entryFormatter)}\n\n") } - unsafeListener { + listenUnsafe { if (logConcurrent || !scope.shouldLog(it.packet) || !networkSide.shouldLog(NetworkSide.SERVER) - ) return@unsafeListener + ) return@listenUnsafe it.packet.logReceived() } - unsafeListener { + listenUnsafe { if (logConcurrent || !scope.shouldLog(it.packet) || !networkSide.shouldLog(NetworkSide.CLIENT) - ) return@unsafeListener + ) return@listenUnsafe it.packet.logSent() } - unsafeConcurrentListener { + listenUnsafeConcurrently { if (!logConcurrent || !scope.shouldLog(it.packet) || !networkSide.shouldLog(NetworkSide.SERVER) - ) return@unsafeConcurrentListener + ) return@listenUnsafeConcurrently it.packet.logReceived() } - unsafeConcurrentListener { + listenUnsafeConcurrently { if (!logConcurrent || !scope.shouldLog(it.packet) || !networkSide.shouldLog(NetworkSide.CLIENT) - ) return@unsafeConcurrentListener + ) return@listenUnsafeConcurrently it.packet.logSent() } diff --git a/common/src/main/kotlin/com/lambda/module/modules/network/Rubberband.kt b/common/src/main/kotlin/com/lambda/module/modules/network/Rubberband.kt index 13868a58a..5b722aae9 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/network/Rubberband.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/network/Rubberband.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.network import com.lambda.event.events.PacketEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.PlayerPacketManager import com.lambda.module.Module import com.lambda.module.tag.ModuleTag @@ -45,13 +45,13 @@ object Rubberband : Module( private val showRubberbandInfo by setting("Show Rubberband Info", true) init { - listener { event -> - if (!showRubberbandInfo) return@listener - if (event.packet !is PlayerPositionLookS2CPacket) return@listener + listen { event -> + if (!showRubberbandInfo) return@listen + if (event.packet !is PlayerPositionLookS2CPacket) return@listen if (PlayerPacketManager.configurations.isEmpty()) { this@Rubberband.warn("Position was reverted") - return@listener + return@listen } val newPos = Vec3d(event.packet.x, event.packet.y, event.packet.z) diff --git a/common/src/main/kotlin/com/lambda/module/modules/network/ServerSpoof.kt b/common/src/main/kotlin/com/lambda/module/modules/network/ServerSpoof.kt index 98de97d0e..ecad05382 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/network/ServerSpoof.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/network/ServerSpoof.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.network import com.lambda.event.events.PacketEvent -import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener +import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.util.Communication.info @@ -44,20 +44,20 @@ object ServerSpoof : Module( private val cancelResourcePack by setting("Cancel Resource Pack Loading", true) init { - unsafeListener { + listenUnsafe { val packet = it.packet - if (packet !is CustomPayloadC2SPacket) return@unsafeListener + if (packet !is CustomPayloadC2SPacket) return@listenUnsafe val payload = packet.payload - if (payload !is BrandCustomPayload) return@unsafeListener - if (!spoofClientBrand || payload.id() != BrandCustomPayload.ID) return@unsafeListener + if (payload !is BrandCustomPayload) return@listenUnsafe + if (!spoofClientBrand || payload.id() != BrandCustomPayload.ID) return@listenUnsafe payload.write(PacketByteBuf(Unpooled.buffer()).writeString(spoofName)) } - unsafeListener { event -> + listenUnsafe { event -> val packet = event.packet - if (!cancelResourcePack) return@unsafeListener - if (packet !is ResourcePackSendS2CPacket) return@unsafeListener + if (!cancelResourcePack) return@listenUnsafe + if (packet !is ResourcePackSendS2CPacket) return@listenUnsafe event.cancel() diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt index 01b906c1d..7dbbbe400 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.player import com.lambda.context.SafeContext import com.lambda.event.events.* -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.DynamicAABB import com.lambda.graphics.renderer.esp.builders.buildFilled import com.lambda.graphics.renderer.esp.builders.buildOutline @@ -83,10 +83,10 @@ object FastBreak : Module( } init { - listener { + listen { if (it.packet !is PlayerActionC2SPacket || it.packet.action != Action.STOP_DESTROY_BLOCK - ) return@listener + ) return@listen connection.sendPacket( PlayerActionC2SPacket( @@ -100,24 +100,24 @@ object FastBreak : Module( ) } - listener { + listen { interaction.blockBreakingCooldown = interaction.blockBreakingCooldown.coerceAtMost(breakDelay) } - listener { + listen { it.progress += world.getBlockState(it.pos) .calcBlockBreakingDelta(player, world, it.pos) * (1 - breakThreshold) } - listener { - if (!renderMode.isEnabled()) return@listener + listen { + if (!renderMode.isEnabled()) return@listen val pos = interaction.currentBreakingPos boxSet = world.getBlockState(pos).getOutlineShape(world, pos).boundingBoxes.toSet() } - listener { - if (!interaction.isBreakingBlock || !renderMode.isEnabled()) return@listener + listen { + if (!interaction.isBreakingBlock || !renderMode.isEnabled()) return@listen val pos = interaction.currentBreakingPos val breakDelta = world.getBlockState(pos).calcBlockBreakingDelta(player, world, pos) diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt b/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt index 0fbf99fcd..fbb08ceaa 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt @@ -20,7 +20,7 @@ package com.lambda.module.modules.player import com.lambda.Lambda.mc import com.lambda.config.groups.IRotationConfig import com.lambda.event.events.* -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.rotation.Rotation import com.lambda.interaction.rotation.Rotation.Companion.rotationTo import com.lambda.interaction.rotation.RotationContext @@ -94,15 +94,15 @@ object Freecam : Module( mc.options.perspective = lastPerspective } - listener(Int.MAX_VALUE) { event -> - if (!rotateToTarget) return@listener - val target = mc.crosshairTarget?.orNull ?: return@listener + listen(Int.MAX_VALUE) { event -> + if (!rotateToTarget) return@listen + val target = mc.crosshairTarget?.orNull ?: return@listen val rotation = player.eyePos.rotationTo(target.pos) event.context = RotationContext(rotation, rotationConfig) } - listener { + listen { rotation = rotation.withDelta( it.deltaYaw * SENSITIVITY_FACTOR, it.deltaPitch * SENSITIVITY_FACTOR @@ -110,7 +110,7 @@ object Freecam : Module( it.cancel() } - listener { event -> + listen { event -> mc.options.perspective = Perspective.FIRST_PERSON // Don't block baritone from working @@ -135,7 +135,7 @@ object Freecam : Module( position += velocity } - listener { + listen { it.cancel() mc.crosshairTarget = rotation @@ -143,7 +143,7 @@ object Freecam : Module( .orMiss // Can't be null (otherwise mc will spam "Null returned as 'hitResult', this shouldn't happen!") } - listener { + listen { disable() } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt b/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt index 79289762f..609305212 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt @@ -20,7 +20,7 @@ package com.lambda.module.modules.player import com.lambda.context.SafeContext import com.lambda.event.events.PlayerEvent import com.lambda.event.events.ScreenHandlerEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.task.Task @@ -50,10 +50,10 @@ object InventoryTweaks : Module( private var lastOpenScreen: ScreenHandler? = null init { - listener { - if (it.action != SlotActionType.PICKUP || it.button != 1) return@listener + listen { + if (it.action != SlotActionType.PICKUP || it.button != 1) return@listen val stack = it.screenHandler.getSlot(it.slot).stack - if (!(instantShulker && stack.item in shulkerBoxes) && !(instantEChest && stack.item == Items.ENDER_CHEST)) return@listener + if (!(instantShulker && stack.item in shulkerBoxes) && !(instantEChest && stack.item == Items.ENDER_CHEST)) return@listen it.cancel() move(it.slot, stack) @@ -67,8 +67,8 @@ object InventoryTweaks : Module( }.start(null) } - listener { event -> - if (event.screenHandler != lastOpenScreen) return@listener + listen { event -> + if (event.screenHandler != lastOpenScreen) return@listen lastOpenScreen = null placedPos?.let { lastBreak = breakAndCollectBlock(it).start(null) diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt index d7ef60656..6e2049e11 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt @@ -20,7 +20,7 @@ package com.lambda.module.modules.player import com.lambda.Lambda.mc import com.lambda.context.SafeContext import com.lambda.event.events.* -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.DynamicAABB import com.lambda.graphics.renderer.esp.builders.buildFilled import com.lambda.graphics.renderer.esp.builders.buildOutline @@ -273,11 +273,11 @@ object PacketMine : Module( private var doubleBreakReturnSlot = 0 init { - listener { + listen { swingingNextAttack = false } - listener { + listen { it.cancel() if (swingOnManual) swingMainHand() @@ -294,10 +294,10 @@ object PacketMine : Module( } else { blockQueue.add(it.pos) } - return@listener + return@listen } - if (blockQueue.contains(it.pos)) return@listener + if (blockQueue.contains(it.pos)) return@listen } currentMiningBlock.forEach { ctx -> @@ -306,9 +306,9 @@ object PacketMine : Module( val primary = breakType.isPrimary() - if (!primary || (breakState == BreakState.ReBreaking && !reBreak.isStandard())) return@listener + if (!primary || (breakState == BreakState.ReBreaking && !reBreak.isStandard())) return@listen - if (miningProgress < breakThreshold) return@listener + if (miningProgress < breakThreshold) return@listen runBetweenHandlers(ProgressStage.EndPre, ProgressStage.EndPost, pos, { lastValidBestTool }) { packetStopBreak(pos) @@ -316,7 +316,7 @@ object PacketMine : Module( onBlockBreak() } - return@listener + return@listen } } @@ -332,17 +332,17 @@ object PacketMine : Module( startBreaking(it.pos) } - listener { - if (!cancelNextSwing) return@listener + listen { + if (!cancelNextSwing) return@listen cancelNextSwing = false it.cancel() } - listener(1) { + listen(1) { updateCounters() - if (shouldWaitForQueuePause()) return@listener + if (shouldWaitForQueuePause()) return@listen currentMiningBlock.forEach { ctx -> ctx?.apply { @@ -508,13 +508,13 @@ object PacketMine : Module( } } - listener { + listen { if (doubleBreakSwapped && doubleBreakSwappedCounter >= 1) { returnToOriginalDoubleBreakSlot() } } - listener { + listen { currentMiningBlock.forEach { ctx -> ctx?.apply { if (it.pos != pos || !isStateBroken(pos.blockState(world), it.state)) return@forEach @@ -532,8 +532,8 @@ object PacketMine : Module( } } - listener { - if (!rotate.isEnabled()) return@listener + listen { + if (!rotate.isEnabled()) return@listen rotationPosition?.let { pos -> lastNonEmptyState?.let { state -> @@ -549,7 +549,7 @@ object PacketMine : Module( expectedRotation = null } - if (!rotated || !waitingToReleaseRotation) return@listener + if (!rotated || !waitingToReleaseRotation) return@listen releaseRotateDelayCounter-- @@ -560,14 +560,14 @@ object PacketMine : Module( } } - listener { - if (!rotate.isEnabled()) return@listener + listen { + if (!rotate.isEnabled()) return@listen expectedRotation?.let { expectedRot -> rotationPosition?.let { pos -> if (it.context != expectedRot) { pausedForRotation = true - return@listener + return@listen } val boxList = lastNonEmptyState?.getOutlineShape(world, pos)?.boundingBoxes?.map { it.offset(pos) } @@ -584,7 +584,7 @@ object PacketMine : Module( pausedForRotation = true } - return@listener + return@listen } } @@ -592,7 +592,7 @@ object PacketMine : Module( pausedForRotation = false } - listener { + listen { renderer.clear() currentMiningBlock.forEach { ctx -> diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt b/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt index 6d8c94dff..d1e83d558 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt @@ -26,7 +26,7 @@ import com.lambda.event.EventFlow.lambdaScope import com.lambda.event.events.KeyboardEvent import com.lambda.event.events.MovementEvent import com.lambda.event.events.RotationEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.rotation.Rotation import com.lambda.interaction.rotation.RotationContext import com.lambda.interaction.rotation.RotationMode @@ -111,8 +111,8 @@ object Replay : Module( .create() init { - listener { - if (mc.currentScreen != null && !mc.options.commandKey.isPressed) return@listener + listen { + if (mc.currentScreen != null && !mc.options.commandKey.isPressed) return@listen when (it.translated) { record -> handleRecord() @@ -123,7 +123,7 @@ object Replay : Module( } } - listener { event -> + listen { event -> when (state) { State.RECORDING -> { buffer?.let { @@ -147,7 +147,7 @@ object Replay : Module( if (cancelOnDeviation && diff > deviationThreshold) { state = State.INACTIVE this@Replay.logError("Replay cancelled due to exceeding deviation threshold.") - return@listener + return@listen } } } @@ -157,7 +157,7 @@ object Replay : Module( } } - listener { event -> + listen { event -> when (state) { State.RECORDING -> { buffer?.rotation?.add(player.rotation) @@ -173,7 +173,7 @@ object Replay : Module( } } - listener { event -> + listen { event -> when (state) { State.RECORDING -> { buffer?.sprint?.add(player.isSprinting) @@ -190,7 +190,7 @@ object Replay : Module( } } - listener { + listen { when (state) { State.RECORDING -> { buffer?.let { @@ -218,7 +218,7 @@ object Replay : Module( State.PLAYING -> { buffer?.let { - if (it.size != 0) return@listener + if (it.size != 0) return@listen if (playMode == PlayMode.LOOP && (repeats < loops || loops < 0)) { if (repeats >= 0) repeats++ @@ -241,7 +241,7 @@ object Replay : Module( color(GuiSettings.primaryColor) { literal(playback?.duration.toString()) } literal(".") }) - return@listener + return@listen } state = State.RECORDING diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/Scaffold.kt b/common/src/main/kotlin/com/lambda/module/modules/player/Scaffold.kt index 218713ec6..333295046 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/Scaffold.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/Scaffold.kt @@ -21,7 +21,7 @@ import com.lambda.config.groups.InteractionSettings import com.lambda.config.groups.RotationSettings import com.lambda.context.SafeContext import com.lambda.event.events.* -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.renderer.esp.DirectionMask import com.lambda.graphics.renderer.esp.DirectionMask.buildSideMesh import com.lambda.graphics.renderer.esp.builders.build @@ -129,11 +129,11 @@ object Scaffold : Module( } ) - listener { + listen { if (sneakTicks > 0) it.sneak = true } - listener { + listen { placeInfo?.let { info -> tickPlacement(info) } @@ -141,7 +141,7 @@ object Scaffold : Module( updateSneaking() } - listener { event -> + listen { event -> buildRenderer(event) } diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt index e42fd2325..de634fec1 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt @@ -23,7 +23,7 @@ import com.lambda.event.events.PlayerEvent import com.lambda.event.events.MovementEvent import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.graphics.buffer.VertexPipeline import com.lambda.graphics.buffer.vertex.attributes.VertexAttrib import com.lambda.graphics.buffer.vertex.attributes.VertexMode @@ -83,12 +83,12 @@ object Particles : Module( private val shader = Shader("renderer/particle", "renderer/particle") init { - listener { + listen { if (environment) spawnForEnvironment() particles.removeIf(Particle::update) } - listener { + listen { // Todo: interpolated tickbased upload? particles.forEach(Particle::build) @@ -102,12 +102,12 @@ object Particles : Module( } } - listener { event -> + listen { event -> spawnForEntity(event.entity) } - listener { - if (!onMove || player.moveDelta < 0.05) return@listener + listen { + if (!onMove || player.moveDelta < 0.05) return@listen spawnForEntity(player) } } diff --git a/common/src/main/kotlin/com/lambda/task/Task.kt b/common/src/main/kotlin/com/lambda/task/Task.kt index f754e9a84..8bf724538 100644 --- a/common/src/main/kotlin/com/lambda/task/Task.kt +++ b/common/src/main/kotlin/com/lambda/task/Task.kt @@ -23,7 +23,7 @@ import com.lambda.event.Event import com.lambda.event.EventFlow import com.lambda.event.Subscriber import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.module.modules.client.TaskFlow import com.lambda.threading.runConcurrent import com.lambda.threading.runGameScheduled @@ -116,7 +116,7 @@ abstract class Task : Nameable { } init { - listener { + listen { parent?.let { it.age++ } @@ -460,7 +460,7 @@ abstract class Task : Nameable { inline fun withListener( crossinline action: SafeContext.(Task) -> Unit ): Task { - listener { + listen { action(this@Task) } return this diff --git a/common/src/main/kotlin/com/lambda/task/tasks/BreakBlock.kt b/common/src/main/kotlin/com/lambda/task/tasks/BreakBlock.kt index 89fcfd365..383f5ea53 100644 --- a/common/src/main/kotlin/com/lambda/task/tasks/BreakBlock.kt +++ b/common/src/main/kotlin/com/lambda/task/tasks/BreakBlock.kt @@ -24,7 +24,7 @@ import com.lambda.context.SafeContext import com.lambda.event.events.RotationEvent import com.lambda.event.events.TickEvent import com.lambda.event.events.WorldEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.construction.context.BreakContext import com.lambda.interaction.visibilty.VisibilityChecker.lookAtBlock import com.lambda.module.modules.client.TaskFlow @@ -77,24 +77,24 @@ class BreakBlock @Ta5kBuilder constructor( } init { - listener { event -> - if (state != State.BREAKING) return@listener - if (!rotate || ctx.instantBreak) return@listener + listen { event -> + if (state != State.BREAKING) return@listen + if (!rotate || ctx.instantBreak) return@listen event.context = lookAtBlock(blockPos, rotation, interact, sides) } - listener { - if (state != State.BREAKING) return@listener - if (!rotate || ctx.instantBreak) return@listener + listen { + if (state != State.BREAKING) return@listen + if (!rotate || ctx.instantBreak) return@listen isValid = it.context.isValid } - listener { + listen { drop?.let { itemDrop -> if (!world.entities.contains(itemDrop)) { success(itemDrop) - return@listener + return@listen } if (player.hotbarAndStorage.none { it.isEmpty }) { @@ -120,7 +120,7 @@ class BreakBlock @Ta5kBuilder constructor( } } - listener { + listen { if (collectDrop && it.entity is ItemEntity && it.entity.pos.isInRange(blockPos.toCenterPos(), 0.5) diff --git a/common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt b/common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt index d5bf3151a..017edf2bf 100644 --- a/common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt +++ b/common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt @@ -21,7 +21,7 @@ import com.lambda.Lambda.LOG import com.lambda.context.SafeContext import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.construction.Blueprint import com.lambda.interaction.construction.Blueprint.Companion.toStructure import com.lambda.interaction.construction.DynamicBlueprint @@ -54,13 +54,13 @@ class BuildTask @Ta5kBuilder constructor( } init { - listener { + listen { previousResults.filterIsInstance().forEach { res -> with(res) { buildRenderer() } } } - listener { + listen { pending.removeIf { if (it.age > placeTimeout) { it.cancel() @@ -74,7 +74,7 @@ class BuildTask @Ta5kBuilder constructor( if (finishOnDone && blueprint.structure.isEmpty()) { failure("Structure is empty") - return@listener + return@listen } val results = blueprint.simulate(player.getCameraPosVec(mc.tickDelta)) @@ -90,18 +90,18 @@ class BuildTask @Ta5kBuilder constructor( pending.add(it) it.start(this@BuildTask, pauseParent = false) } - return@listener + return@listen } if (pending.isNotEmpty()) { - return@listener + return@listen } - val result = results.minOrNull() ?: return@listener + val result = results.minOrNull() ?: return@listen when { !result.rank.solvable -> { // info("Unsolvable: $result") - if (!blueprint.isDone(this)) return@listener + if (!blueprint.isDone(this)) return@listen success(Unit) } diff --git a/common/src/main/kotlin/com/lambda/task/tasks/InventoryTask.kt b/common/src/main/kotlin/com/lambda/task/tasks/InventoryTask.kt index 6b4075808..f6392ed96 100644 --- a/common/src/main/kotlin/com/lambda/task/tasks/InventoryTask.kt +++ b/common/src/main/kotlin/com/lambda/task/tasks/InventoryTask.kt @@ -19,7 +19,7 @@ package com.lambda.task.tasks import com.lambda.context.SafeContext import com.lambda.event.events.TickEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.material.StackSelection import com.lambda.module.modules.client.TaskFlow import com.lambda.task.Task @@ -54,7 +54,7 @@ class InventoryTask( init { // ToDo: Needs smart code to move as efficient as possible. // Also should handle overflow etc. Should be more generic - listener { + listen { val moved = selector.filterSlots(to) .filter { it.hasStack() } .sumOf { it.stack.count } >= selector.count diff --git a/common/src/main/kotlin/com/lambda/task/tasks/OpenContainer.kt b/common/src/main/kotlin/com/lambda/task/tasks/OpenContainer.kt index 77dea5a3e..eba1a36d1 100644 --- a/common/src/main/kotlin/com/lambda/task/tasks/OpenContainer.kt +++ b/common/src/main/kotlin/com/lambda/task/tasks/OpenContainer.kt @@ -21,7 +21,7 @@ import com.lambda.config.groups.IRotationConfig import com.lambda.config.groups.InteractionConfig import com.lambda.event.events.RotationEvent import com.lambda.event.events.ScreenHandlerEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.visibilty.VisibilityChecker.lookAtBlock import com.lambda.module.modules.client.TaskFlow import com.lambda.task.Task @@ -50,8 +50,8 @@ class OpenContainer( } init { - listener { - if (state != State.OPENING) return@listener + listen { + if (state != State.OPENING) return@listen screenHandler = it.screenHandler state = State.SLOT_LOADING @@ -59,33 +59,33 @@ class OpenContainer( if (!waitForSlotLoad) success(it.screenHandler) } - listener { - if (screenHandler != it.screenHandler) return@listener + listen { + if (screenHandler != it.screenHandler) return@listen state = State.SCOPING screenHandler = null } - listener { - if (state != State.SLOT_LOADING) return@listener + listen { + if (state != State.SLOT_LOADING) return@listen screenHandler?.let { success(it) } } - listener { event -> - if (!rotate) return@listener + listen { event -> + if (!rotate) return@listen event.context = lookAtBlock(blockPos, rotation, interact, sides) } - listener { - if (!rotate) return@listener - if (state != State.SCOPING) return@listener - if (!it.context.isValid) return@listener + listen { + if (!rotate) return@listen + if (state != State.SCOPING) return@listen + if (!it.context.isValid) return@listen if (inScope++ >= interact.scopeThreshold) { - val hitResult = it.context.hitResult?.blockResult ?: return@listener + val hitResult = it.context.hitResult?.blockResult ?: return@listen interaction.interactBlock(player, Hand.MAIN_HAND, hitResult) state = State.OPENING diff --git a/common/src/main/kotlin/com/lambda/task/tasks/PlaceBlock.kt b/common/src/main/kotlin/com/lambda/task/tasks/PlaceBlock.kt index 7801f074d..6e2c9d293 100644 --- a/common/src/main/kotlin/com/lambda/task/tasks/PlaceBlock.kt +++ b/common/src/main/kotlin/com/lambda/task/tasks/PlaceBlock.kt @@ -23,7 +23,7 @@ import com.lambda.context.SafeContext import com.lambda.event.events.RotationEvent import com.lambda.event.events.TickEvent import com.lambda.event.events.WorldEvent -import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.construction.context.PlaceContext import com.lambda.module.modules.client.TaskFlow import com.lambda.task.Task @@ -64,30 +64,30 @@ class PlaceBlock @Ta5kBuilder constructor( } init { - listener { event -> - if (state != State.ROTATING) return@listener - if (!rotate) return@listener + listen { event -> + if (state != State.ROTATING) return@listen + if (!rotate) return@listen event.context = ctx.rotation } - listener { event -> - if (state != State.ROTATING) return@listener - if (!rotate) return@listener - if (event.context != ctx.rotation) return@listener - if (!event.context.isValid) return@listener + listen { event -> + if (state != State.ROTATING) return@listen + if (!rotate) return@listen + if (event.context != ctx.rotation) return@listen + if (!event.context.isValid) return@listen state = State.PLACING } - listener { - if (state != State.PLACING) return@listener + listen { + if (state != State.PLACING) return@listen if (findOutIfNeeded) placeBlock() findOutIfNeeded = true } - listener { - if (it.pos != ctx.resultingPos) return@listener + listen { + if (it.pos != ctx.resultingPos) return@listen if (ctx.targetState.matches(it.state, it.pos, world)) { finish() diff --git a/common/src/main/kotlin/com/lambda/threading/Threading.kt b/common/src/main/kotlin/com/lambda/threading/Threading.kt index 3a0405387..bb329a6be 100644 --- a/common/src/main/kotlin/com/lambda/threading/Threading.kt +++ b/common/src/main/kotlin/com/lambda/threading/Threading.kt @@ -23,6 +23,7 @@ import com.lambda.context.SafeContext import com.lambda.event.EventFlow import com.mojang.blaze3d.systems.RenderSystem.isOnRenderThread import com.mojang.blaze3d.systems.RenderSystem.recordRenderCall +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.future.await import kotlinx.coroutines.launch @@ -52,13 +53,13 @@ inline fun runSafe(block: SafeContext.() -> T) = * * @param block The block of code to be executed concurrently. */ -inline fun runConcurrent(crossinline block: suspend () -> Unit) = - EventFlow.lambdaScope.launch { +inline fun runConcurrent(scheduler: CoroutineDispatcher = Dispatchers.Default, crossinline block: suspend () -> Unit) = + EventFlow.lambdaScope.launch(scheduler) { block() } inline fun runIO(crossinline block: suspend () -> Unit) = - EventFlow.lambdaScope.launch(Dispatchers.IO) { + runConcurrent(Dispatchers.IO) { block() }