Skip to content

Commit 3886b6d

Browse files
committed
cancel fake player attacks
1 parent b9e4384 commit 3886b6d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/main/kotlin/com/lambda/module/modules/combat/FakePlayer.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.lambda.module.modules.combat
1919

2020
import com.lambda.context.SafeContext
2121
import com.lambda.event.events.ConnectionEvent
22+
import com.lambda.event.events.PlayerEvent
2223
import com.lambda.event.events.TickEvent
2324
import com.lambda.event.listener.SafeListener.Companion.listen
2425
import com.lambda.event.listener.SafeListener.Companion.listenConcurrently
@@ -27,6 +28,7 @@ import com.lambda.module.tag.ModuleTag
2728
import com.lambda.network.mojang.getProfile
2829
import com.lambda.threading.onShutdown
2930
import com.lambda.util.Timer
31+
import com.lambda.util.player.FakePlayerId
3032
import com.lambda.util.player.spawnFakePlayer
3133
import com.mojang.authlib.GameProfile
3234
import com.mojang.datafixers.util.Either
@@ -70,6 +72,10 @@ object FakePlayer : Module(
7072
cachedProfiles.getOrPut(playerName) { fetchProfile(playerName) }
7173
}
7274

75+
listen<PlayerEvent.Attack.Entity> {
76+
if (it.entity.id == FakePlayerId) it.cancel()
77+
}
78+
7379
listen<ConnectionEvent.Connect.Pre> { disable() }
7480
onShutdown { disable() }
7581
onDisable { fakePlayer?.discard(); fakePlayer = null }

src/main/kotlin/com/lambda/util/player/PlayerUtils.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket
2929
import net.minecraft.util.Hand
3030
import net.minecraft.world.GameMode
3131

32+
const val FakePlayerId = -2024-4-20
33+
3234
val SafeContext.gamemode: GameMode
3335
get() = interaction.currentGameMode
3436

@@ -59,7 +61,7 @@ fun SafeContext.spawnFakePlayer(
5961
copyFrom(reference)
6062

6163
playerListEntry = PlayerListEntry(profile, false)
62-
id = -2024 - 4 - 20
64+
id = FakePlayerId
6365
}
6466

6567
if (addToWorld) world.addEntity(entity)

0 commit comments

Comments
 (0)