diff --git a/MinecraftClient/Mapping/CombatEventType.cs b/MinecraftClient/Mapping/CombatEventType.cs
new file mode 100644
index 00000000..cdafa893
--- /dev/null
+++ b/MinecraftClient/Mapping/CombatEventType.cs
@@ -0,0 +1,9 @@
+namespace MinecraftClient.Mapping
+{
+ public enum CombatEventType
+ {
+ EnterCombat = 0,
+ EndCombat,
+ EntityDead
+ }
+}
diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs
index 16bb2e9d..04a853b1 100644
--- a/MinecraftClient/McClient.cs
+++ b/MinecraftClient/McClient.cs
@@ -2878,6 +2878,19 @@ namespace MinecraftClient
DispatchBotEvent(bot => bot.OnPlayerLeave(uuid, username));
}
+ //
+ /// This method is called when a player has been killed by another entity
+ ///
+ /// Victim's entity
+ /// Killer's entity
+ public void OnPlayerKilled(int killerEntityId, string chatMessage)
+ {
+ if (!entities.ContainsKey(killerEntityId))
+ return;
+
+ DispatchBotEvent(bot => bot.OnKilled(entities[killerEntityId], chatMessage));
+ }
+
///
/// Called when a plugin channel message was sent from the server.
///
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs
index 70670e4b..02d3068e 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs
@@ -596,6 +596,33 @@ namespace MinecraftClient.Protocol.Handlers
Acknowledge(chat);
handler.OnTextReceived(chat);
}
+ break;
+ case PacketTypesIn.CombatEvent:
+ // 1.8 - 1.16.5
+ if (protocolVersion >= MC_1_8_Version && protocolVersion <= MC_1_16_5_Version)
+ {
+ CombatEventType eventType = (CombatEventType)dataTypes.ReadNextVarInt(packetData);
+
+ if (eventType == CombatEventType.EntityDead)
+ {
+ dataTypes.SkipNextVarInt(packetData);
+
+ handler.OnPlayerKilled(
+ dataTypes.ReadNextInt(packetData),
+ ChatParser.ParseText(dataTypes.ReadNextString(packetData))
+ );
+ }
+ }
+
+ break;
+ case PacketTypesIn.DeathCombatEvent:
+ dataTypes.SkipNextVarInt(packetData);
+
+ handler.OnPlayerKilled(
+ dataTypes.ReadNextInt(packetData),
+ ChatParser.ParseText(dataTypes.ReadNextString(packetData))
+ );
+
break;
case PacketTypesIn.MessageHeader:
if (protocolVersion >= MC_1_19_2_Version)
diff --git a/MinecraftClient/Protocol/IMinecraftComHandler.cs b/MinecraftClient/Protocol/IMinecraftComHandler.cs
index de3a6ede..1ac38a39 100644
--- a/MinecraftClient/Protocol/IMinecraftComHandler.cs
+++ b/MinecraftClient/Protocol/IMinecraftComHandler.cs
@@ -159,6 +159,13 @@ namespace MinecraftClient.Protocol
/// UUID of the player
void OnPlayerLeave(Guid uuid);
+ ///
+ /// This method is called when a player has been killed by another entity
+ ///
+ /// Killer's entity if
+ /// message sent in chat when player is killed
+ void OnPlayerKilled(int killerEntityId, string chatMessage);
+
///
/// Called when the server sets the new location for the player
///
diff --git a/MinecraftClient/Scripting/ChatBot.cs b/MinecraftClient/Scripting/ChatBot.cs
index 1c8272b1..e8ec7cff 100644
--- a/MinecraftClient/Scripting/ChatBot.cs
+++ b/MinecraftClient/Scripting/ChatBot.cs
@@ -417,7 +417,15 @@ namespace MinecraftClient
public virtual void OnPlayerLeave(Guid uuid, string? name) { }
///
- /// Called when the player deaths
+ /// This method is called when a player has been killed by another entity
+ ///
+ /// Killer's entity
+ /// message sent in chat when player is killed
+ public virtual void OnKilled(Entity killerEntity, string chatMessage) { }
+
+ ///
+ /// Called when the player dies
+ /// For getting the info about the player/entity who killed the player use OnPlayerKilled
///
public virtual void OnDeath() { }