Add player join/leave event to ChatBot API (#1181)

* Add player join/leave event to ChatBot API (#1180)
* Add method documentation
* Dispatch Join/Leave after updating player list
Co-authored-by: ORelio <ORelio@users.noreply.github.com>
This commit is contained in:
ReinforceZwei 2020-08-06 21:57:23 +08:00 committed by GitHub
parent a17d60047a
commit 4a8fb08f4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View file

@ -299,6 +299,20 @@ namespace MinecraftClient
/// <param name="inventoryId"></param> /// <param name="inventoryId"></param>
public virtual void OnInventoryClose(int inventoryId) { } public virtual void OnInventoryClose(int inventoryId) { }
/// <summary>
/// Called when a player joined the game
/// </summary>
/// <param name="uuid">UUID of the player</param>
/// <param name="name">Name of the player</param>
public virtual void OnPlayerJoin(Guid uuid, string name) { }
/// <summary>
/// Called when a player left the game
/// </summary>
/// <param name="uuid">UUID of the player</param>
/// <param name="name">Name of the player</param>
public virtual void OnPlayerLeave(Guid uuid, string name) { }
/* =================================================================== */ /* =================================================================== */
/* ToolBox - Methods below might be useful while creating your bot. */ /* ToolBox - Methods below might be useful while creating your bot. */
/* You should not need to interact with other classes of the program. */ /* You should not need to interact with other classes of the program. */

View file

@ -1759,6 +1759,8 @@ namespace MinecraftClient
{ {
onlinePlayers[uuid] = name; onlinePlayers[uuid] = name;
} }
DispatchBotEvent(bot => bot.OnPlayerJoin(uuid, name));
} }
/// <summary> /// <summary>
@ -1771,6 +1773,8 @@ namespace MinecraftClient
{ {
onlinePlayers.Remove(uuid); onlinePlayers.Remove(uuid);
} }
DispatchBotEvent(bot => bot.OnPlayerLeave(uuid, onlinePlayers[uuid]));
} }
/// <summary> /// <summary>