Fix crash when a bot unloads in OnDisconnect()

See #817
This commit is contained in:
ORelio 2019-12-08 20:18:40 +01:00
parent d1674a2d74
commit 64d62373c9

View file

@ -353,7 +353,7 @@ namespace MinecraftClient
/// </summary> /// </summary>
public void Disconnect() public void Disconnect()
{ {
foreach (ChatBot bot in bots) foreach (ChatBot bot in bots.ToArray())
bot.OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Disconnected"); bot.OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Disconnected");
botsOnHold.Clear(); botsOnHold.Clear();
@ -433,7 +433,7 @@ namespace MinecraftClient
Settings.MCSettings_ChatColors, Settings.MCSettings_ChatColors,
Settings.MCSettings_Skin_All, Settings.MCSettings_Skin_All,
Settings.MCSettings_MainHand); Settings.MCSettings_MainHand);
foreach (ChatBot bot in bots) foreach (ChatBot bot in bots.ToArray())
bot.AfterGameJoined(); bot.AfterGameJoined();
if (inventoryHandlingRequested) if (inventoryHandlingRequested)
{ {
@ -753,7 +753,7 @@ namespace MinecraftClient
break; break;
} }
foreach (ChatBot bot in bots) foreach (ChatBot bot in bots.ToArray())
will_restart |= bot.OnDisconnect(reason, message); will_restart |= bot.OnDisconnect(reason, message);
if (!will_restart) if (!will_restart)