Skip to content

Commit c28de42

Browse files
committed
fix(Backtrack): npe by race condition
fixes #7289
1 parent dfdaa60 commit c28de42

File tree

1 file changed

+8
-8
lines changed
  • src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/backtrack

1 file changed

+8
-8
lines changed

src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/backtrack/ModuleBacktrack.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,18 @@ object ModuleBacktrack : ClientModule("Backtrack", Category.COMBAT) {
146146
val positionPacket = packet is EntityPositionS2CPacket && packet.entityId == target?.id
147147
val syncPacket = packet is EntityPositionSyncS2CPacket && packet.id == target?.id
148148
if (entityPacket || positionPacket || syncPacket) {
149-
val pos = if (packet is EntityS2CPacket) {
150-
position?.withDelta(packet.deltaX.toLong(), packet.deltaY.toLong(), packet.deltaZ.toLong())
151-
} else if (packet is EntityPositionS2CPacket) {
152-
Vec3d(packet.change.position.x, packet.change.position.y, packet.change.position.z)
153-
} else {
154-
(packet as EntityPositionSyncS2CPacket).values.position()
149+
val pos = when (packet) {
150+
is EntityS2CPacket ->
151+
position?.withDelta(packet.deltaX.toLong(), packet.deltaY.toLong(), packet.deltaZ.toLong())
152+
is EntityPositionS2CPacket ->
153+
Vec3d(packet.change.position.x, packet.change.position.y, packet.change.position.z)
154+
else -> (packet as EntityPositionSyncS2CPacket).values.position()
155155
}
156-
157156
position?.setPos(pos)
158157

159158
// Is the target's actual position closer than its tracked position?
160-
if (target!!.squareBoxedDistanceTo(player, pos!!) < target!!.squaredBoxedDistanceTo(player)) {
159+
val target = target ?: return@handler
160+
if (target.squareBoxedDistanceTo(player, pos!!) < target.squaredBoxedDistanceTo(player)) {
161161
// Process all packets. We want to be able to hit the enemy, not the opposite.
162162
processPackets(true)
163163
// And stop right here. No need to cancel further packets.

0 commit comments

Comments
 (0)