Skip to content

Commit

Permalink
Include death message in player-died event metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
4Ply committed Dec 27, 2024
1 parent d4b9961 commit eff71e0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/kotlin/org/trackedout/AgroNet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,18 @@ object AgroNet : ModInitializer {

ServerLivingEntityEvents.AFTER_DEATH.register { entity, source ->
if (entity is ServerPlayerEntity) {
val deathMessage = source.getDeathMessage(entity)?.string
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})")
logger.info("Player ${entity.gameProfile.name} died at ${entity.pos}, killer: $killerName (${killerType}), message: $deathMessage")

val metadata = mutableMapOf(
"killer" to killerName,
"killer-type" to killerType,
)
if (deathMessage != null) {
metadata["death-message"] = deathMessage
}

eventsApi.eventsPost(
Event(
Expand All @@ -314,10 +323,7 @@ object AgroNet : ModInitializer {
y = entity.pos.y,
z = entity.pos.z,
count = 1,
metadata = mapOf(
"killer" to killerName,
"killer-type" to killerType,
)
metadata = metadata,
)
)
}
Expand Down

0 comments on commit eff71e0

Please sign in to comment.