Skip to content

Commit 98bdcc8

Browse files
committed
Reformat: RocketExtend module
1 parent 086cd48 commit 98bdcc8

File tree

1 file changed

+22
-40
lines changed

1 file changed

+22
-40
lines changed

common/src/main/kotlin/com/lambda/module/modules/movement/RocketExtend.kt

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.lambda.module.Module
66
import com.lambda.module.tag.ModuleTag
77
import com.lambda.threading.runSafe
88
import com.lambda.util.Communication.info
9+
import net.minecraft.entity.Entity
910
import net.minecraft.entity.projectile.FireworkRocketEntity
1011
import net.minecraft.network.packet.c2s.common.CommonPongC2SPacket
1112
import net.minecraft.network.packet.s2c.play.EntitiesDestroyS2CPacket
@@ -16,54 +17,35 @@ object RocketExtend : Module(
1617
description = "Extends rocket length on grim",
1718
defaultTags = setOf(ModuleTag.MOVEMENT)
1819
) {
19-
var extendedRockets: MutableList<FireworkRocketEntity> = mutableListOf();
20-
var pingPacket: CommonPongC2SPacket? = null;
20+
private var extendedRockets = mutableListOf<FireworkRocketEntity>()
21+
private var pingPacket: CommonPongC2SPacket? = null
22+
2123
init {
22-
onDisable {
23-
if (extendedRockets.isNotEmpty()) reset()
24-
}
2524
listener<PacketEvent.Receive.Pre> { event ->
26-
when (event.packet) {
27-
is EntitiesDestroyS2CPacket -> {
28-
val rockets = event.packet.entityIds.map { id ->
29-
world.getEntityById(id)
30-
}.filter { entity ->
31-
entity is FireworkRocketEntity && entity.shooter?.equals(this.player) == true
32-
}.filterNotNull().map {it as FireworkRocketEntity}
33-
34-
if (rockets.isEmpty()) return@listener
35-
extendedRockets.addAll(rockets)
36-
event.packet.entityIds.removeAll(rockets.map { it.id }.toSet())
37-
38-
this@RocketExtend.info("RocketExtend triggered")
39-
}
40-
is PlayerPositionLookS2CPacket -> {
41-
if(extendedRockets.isNotEmpty()) reset()
42-
}
25+
if (event.packet is PlayerPositionLookS2CPacket) reset()
26+
27+
if (event.packet is EntitiesDestroyS2CPacket) {
28+
val rockets = event.packet.entityIds.map(world::getEntityById)
29+
.filter { it is FireworkRocketEntity && it.shooter == player }
30+
.mapNotNull { it as? FireworkRocketEntity }
31+
.also { event.packet.entityIds.removeAll(it.map(FireworkRocketEntity::getId)) }
32+
extendedRockets.addAll(rockets)
4333
}
4434
}
45-
listener<PacketEvent.Send.Pre> { event ->
46-
when (event.packet) {
47-
is CommonPongC2SPacket -> {
48-
if (extendedRockets.isNotEmpty()) {
49-
pingPacket = event.packet
5035

51-
event.cancel()
52-
}
53-
}
54-
}
36+
listener<PacketEvent.Send.Pre> { event ->
37+
if (event.packet !is CommonPongC2SPacket) return@listener
38+
pingPacket = event.packet
39+
event.cancel()
5540
}
56-
}
57-
58-
fun reset() {
59-
this@RocketExtend.info("Reset RocketExtend")
6041

61-
runSafe {
62-
extendedRockets.forEach { it.discard() }
63-
if (pingPacket != null) connection.sendPacket(pingPacket)
64-
}
42+
onDisable(::reset)
43+
}
6544

45+
private fun reset() = runSafe {
46+
extendedRockets.forEach(FireworkRocketEntity::discard)
6647
extendedRockets.clear()
48+
pingPacket?.let(connection::sendPacket)
6749
pingPacket = null
6850
}
69-
}
51+
}

0 commit comments

Comments
 (0)