Skip to content

Commit

Permalink
Send a 'player-died' event with the mob name + type
Browse files Browse the repository at this point in the history
  • Loading branch information
4Ply committed Dec 27, 2024
1 parent b09a9ea commit d4b9961
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/kotlin/org/trackedout/AgroNet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.netty.buffer.Unpooled
import me.lucko.fabric.api.permissions.v0.Permissions
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
import net.fabricmc.fabric.api.networking.v1.PacketSender
Expand Down Expand Up @@ -299,6 +300,29 @@ object AgroNet : ModInitializer {
}
}, 0, 15, TimeUnit.SECONDS)

ServerLivingEntityEvents.AFTER_DEATH.register { entity, source ->
if (entity is ServerPlayerEntity) {
val killerName = source.attacker?.displayName?.string ?: "unknown"
val killerType = source.attacker?.type?.name?.string ?: "unknown"
logger.info("Player ${entity.gameProfile.name} died at ${entity.pos}, killer: $killerName (${killerType})")

eventsApi.eventsPost(
Event(
name = "player-died",
player = entity.gameProfile.name,
x = entity.pos.x,
y = entity.pos.y,
z = entity.pos.z,
count = 1,
metadata = mapOf(
"killer" to killerName,
"killer-type" to killerType,
)
)
)
}
}

ServerLifecycleEvents.SERVER_STARTED.register { server: MinecraftServer ->
val taskManager = TaskManagement(tasksApi, serverName)
threadPool.scheduleAtFixedRate({
Expand Down

0 comments on commit d4b9961

Please sign in to comment.