11package com.lambda.module.modules.movement
22
3+ import com.lambda.context.SafeContext
34import com.lambda.event.events.PacketEvent
45import com.lambda.event.listener.SafeListener.Companion.listener
56import com.lambda.module.Module
67import com.lambda.module.tag.ModuleTag
78import com.lambda.threading.runSafe
9+ import com.lambda.util.collections.filterPointer
810import net.minecraft.entity.projectile.FireworkRocketEntity
911import net.minecraft.network.packet.c2s.common.CommonPongC2SPacket
1012import net.minecraft.network.packet.s2c.play.EntitiesDestroyS2CPacket
@@ -25,24 +27,24 @@ object RocketExtend : Module(
2527 if (event.packet is PlayerPositionLookS2CPacket ) reset()
2628
2729 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).toSet()) }
32- extendedRockets.addAll(rockets)
30+ event.packet.entityIds.map(world::getEntityById)
31+ .filterPointer(extendedRockets, { event.packet.entityIds.removeInt(it.id) }) { rocket -> rocket.shooter == player }
3332 }
3433 }
3534
3635 listener<PacketEvent .Send .Pre > { event ->
3736 if (event.packet !is CommonPongC2SPacket ) return @listener
37+
3838 if (extendedRockets.isEmpty()) {
3939 lastPingTime = System .currentTimeMillis()
4040 return @listener
4141 }
42+
4243 if (System .currentTimeMillis() - lastPingTime > keepAliveTime * 1000 ) {
4344 reset()
4445 return @listener
4546 }
47+
4648 pingPacket = event.packet
4749 event.cancel()
4850 }
@@ -52,7 +54,7 @@ object RocketExtend : Module(
5254 }
5355 }
5456
55- private fun reset () = runSafe {
57+ private fun SafeContext. reset () {
5658 extendedRockets.forEach(FireworkRocketEntity ::discard)
5759 extendedRockets.clear()
5860 pingPacket?.let (connection::sendPacket)
0 commit comments