mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Added Player Killed event (Combat and CombatDeath packets).
This commit is contained in:
parent
01eee22921
commit
80e227c3a7
5 changed files with 65 additions and 1 deletions
9
MinecraftClient/Mapping/CombatEventType.cs
Normal file
9
MinecraftClient/Mapping/CombatEventType.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace MinecraftClient.Mapping
|
||||||
|
{
|
||||||
|
public enum CombatEventType
|
||||||
|
{
|
||||||
|
EnterCombat = 0,
|
||||||
|
EndCombat,
|
||||||
|
EntityDead
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2878,6 +2878,19 @@ namespace MinecraftClient
|
||||||
DispatchBotEvent(bot => bot.OnPlayerLeave(uuid, username));
|
DispatchBotEvent(bot => bot.OnPlayerLeave(uuid, username));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <summary>
|
||||||
|
/// This method is called when a player has been killed by another entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerEntity">Victim's entity</param>
|
||||||
|
/// <param name="killerEntity">Killer's entity</param>
|
||||||
|
public void OnPlayerKilled(int killerEntityId, string chatMessage)
|
||||||
|
{
|
||||||
|
if (!entities.ContainsKey(killerEntityId))
|
||||||
|
return;
|
||||||
|
|
||||||
|
DispatchBotEvent(bot => bot.OnKilled(entities[killerEntityId], chatMessage));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when a plugin channel message was sent from the server.
|
/// Called when a plugin channel message was sent from the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -596,6 +596,33 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
Acknowledge(chat);
|
Acknowledge(chat);
|
||||||
handler.OnTextReceived(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;
|
break;
|
||||||
case PacketTypesIn.MessageHeader:
|
case PacketTypesIn.MessageHeader:
|
||||||
if (protocolVersion >= MC_1_19_2_Version)
|
if (protocolVersion >= MC_1_19_2_Version)
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,13 @@ namespace MinecraftClient.Protocol
|
||||||
/// <param name="uuid">UUID of the player</param>
|
/// <param name="uuid">UUID of the player</param>
|
||||||
void OnPlayerLeave(Guid uuid);
|
void OnPlayerLeave(Guid uuid);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This method is called when a player has been killed by another entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="killerEntityId">Killer's entity if</param>
|
||||||
|
/// <param name="chatMessage">message sent in chat when player is killed</param>
|
||||||
|
void OnPlayerKilled(int killerEntityId, string chatMessage);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the server sets the new location for the player
|
/// Called when the server sets the new location for the player
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -417,7 +417,15 @@ namespace MinecraftClient
|
||||||
public virtual void OnPlayerLeave(Guid uuid, string? name) { }
|
public virtual void OnPlayerLeave(Guid uuid, string? name) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the player deaths
|
/// This method is called when a player has been killed by another entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="killerEntity">Killer's entity</param>
|
||||||
|
/// <param name="chatMessage">message sent in chat when player is killed</param>
|
||||||
|
public virtual void OnKilled(Entity killerEntity, string chatMessage) { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the player dies
|
||||||
|
/// For getting the info about the player/entity who killed the player use OnPlayerKilled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnDeath() { }
|
public virtual void OnDeath() { }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue