public void StartPlugin(RadegastInstance inst)\r
{\r
Instance = inst;\r
+ Instance.ClientChanged += new EventHandler<ClientChangedEventArgs>(Instance_ClientChanged);\r
\r
Alice = new AIMLbot.Bot();\r
Alice.isAcceptingUserInput = false;\r
}\r
\r
// Events\r
- Client.Self.ChatFromSimulator += new EventHandler<ChatEventArgs>(Self_ChatFromSimulator);\r
- Client.Self.IM += new EventHandler<InstantMessageEventArgs>(Self_IM);\r
- Client.Avatars.AvatarPropertiesReply += new EventHandler<AvatarPropertiesReplyEventArgs>(Avatars_AvatarPropertiesReply);\r
- Client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected);\r
-\r
+ RegisterClientEvents(Client);\r
}\r
\r
\r
Instance.MainForm.ToolsMenu.DropDownItems.Remove(MenuButton);\r
\r
// Unregister events\r
+ UnregisterClientEvents(Client);\r
+ }\r
+\r
+ private void RegisterClientEvents(GridClient client)\r
+ {\r
+ Client.Self.ChatFromSimulator += new EventHandler<ChatEventArgs>(Self_ChatFromSimulator);\r
+ Client.Self.IM += new EventHandler<InstantMessageEventArgs>(Self_IM);\r
+ Client.Avatars.AvatarPropertiesReply += new EventHandler<AvatarPropertiesReplyEventArgs>(Avatars_AvatarPropertiesReply);\r
+ Client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected);\r
+ }\r
+\r
+ private void UnregisterClientEvents(GridClient client)\r
+ {\r
Client.Self.ChatFromSimulator -= new EventHandler<ChatEventArgs>(Self_ChatFromSimulator);\r
Client.Self.IM -= new EventHandler<InstantMessageEventArgs>(Self_IM);\r
Client.Avatars.AvatarPropertiesReply -= new EventHandler<AvatarPropertiesReplyEventArgs>(Avatars_AvatarPropertiesReply);\r
Client.Network.OnConnected -= new NetworkManager.ConnectedCallback(Network_OnConnected);\r
}\r
\r
+ void Instance_ClientChanged(object sender, ClientChangedEventArgs e)\r
+ {\r
+ UnregisterClientEvents(e.OldClient);\r
+ RegisterClientEvents(Client);\r
+ }\r
+ \r
void Network_OnConnected(object sender)\r
{\r
Alice.GlobalSettings.updateSetting("name", FirstName(Client.Self.Name));\r