Add an "AfterGameJoined" method to ChatBot.cs.

Since messages can't be sent in Initialize(), a method that's called when the chat bot can first send messages is needed.  This method is called when the login completes or when the bot is loaded if the login is already been completed.
This commit is contained in:
Pokechu22 2016-02-07 14:47:03 -08:00
parent 1ea8f119d9
commit 6d4ec86619
2 changed files with 24 additions and 1 deletions

View file

@ -75,10 +75,22 @@ namespace MinecraftClient
/// <summary>
/// Anything you want to initialize your bot, will be called on load by MinecraftCom
///
/// NOTE: Chat messages cannot be sent at this point in the login process. If you want to send
/// a message when the bot is loaded, use AfterGameJoined.
/// </summary>
public virtual void Initialize() { }
/// <summary>
/// Called after the server has been joined successfully and chat messages are able to be sent.
///
/// NOTE: This is not always right after joining the server - if the bot was loaded after logging
/// in this is still called.
/// </summary>
public virtual void AfterGameJoined() { }
/// <summary>
/// Will be called every ~100ms (10fps) if loaded in MinecraftCom
/// </summary>

View file

@ -27,7 +27,16 @@ namespace MinecraftClient
private readonly List<ChatBot> bots = new List<ChatBot>();
private static readonly List<ChatBots.Script> scripts_on_hold = new List<ChatBots.Script>();
public void BotLoad(ChatBot b) { b.SetHandler(this); bots.Add(b); b.Initialize(); Settings.SingleCommand = ""; }
public void BotLoad(ChatBot b) {
b.SetHandler(this);
bots.Add(b);
b.Initialize();
if (this.handler != null)
{
b.AfterGameJoined();
}
Settings.SingleCommand = "";
}
public void BotUnLoad(ChatBot b) {
bots.RemoveAll(item => object.ReferenceEquals(item, b));
@ -351,6 +360,8 @@ namespace MinecraftClient
{
if (!String.IsNullOrWhiteSpace(Settings.BrandInfo))
handler.SendBrandInfo(Settings.BrandInfo.Trim());
foreach (ChatBot bot in bots)
bot.AfterGameJoined();
}
/// <summary>