From 4a8fb08f4bb2037c68f166acc6ea30967c861ce2 Mon Sep 17 00:00:00 2001 From: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com> Date: Thu, 6 Aug 2020 21:57:23 +0800 Subject: [PATCH] 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 --- MinecraftClient/ChatBot.cs | 14 ++++++++++++++ MinecraftClient/McClient.cs | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index d362f4a0..d4cdf4da 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -299,6 +299,20 @@ namespace MinecraftClient /// public virtual void OnInventoryClose(int inventoryId) { } + /// + /// Called when a player joined the game + /// + /// UUID of the player + /// Name of the player + public virtual void OnPlayerJoin(Guid uuid, string name) { } + + /// + /// Called when a player left the game + /// + /// UUID of the player + /// Name of the player + public virtual void OnPlayerLeave(Guid uuid, string name) { } + /* =================================================================== */ /* ToolBox - Methods below might be useful while creating your bot. */ /* You should not need to interact with other classes of the program. */ diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index e32c22be..583234d3 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -1759,6 +1759,8 @@ namespace MinecraftClient { onlinePlayers[uuid] = name; } + + DispatchBotEvent(bot => bot.OnPlayerJoin(uuid, name)); } /// @@ -1771,6 +1773,8 @@ namespace MinecraftClient { onlinePlayers.Remove(uuid); } + + DispatchBotEvent(bot => bot.OnPlayerLeave(uuid, onlinePlayers[uuid])); } ///