diff --git a/MCGalaxy/Bots/PlayerBot.cs b/MCGalaxy/Bots/PlayerBot.cs index 7e0a09730..09f425b83 100644 --- a/MCGalaxy/Bots/PlayerBot.cs +++ b/MCGalaxy/Bots/PlayerBot.cs @@ -81,17 +81,7 @@ namespace MCGalaxy { if (save) BotsFile.Save(bot.level); } - public static void UnloadFromLevel(Level lvl) { - BotsFile.Save(lvl); - RemoveLoadedBots(lvl, false); - } - - public static void RemoveAllFromLevel(Level lvl) { - RemoveLoadedBots(lvl, false); - BotsFile.Save(lvl); - } - - static void RemoveLoadedBots(Level lvl, bool save) { + internal static void RemoveLoadedBots(Level lvl, bool save) { PlayerBot[] bots = lvl.Bots.Items; for (int i = 0; i < bots.Length; i++) { Remove(bots[i], save); diff --git a/MCGalaxy/Commands/Bots/CmdBot.cs b/MCGalaxy/Commands/Bots/CmdBot.cs index 0c17debdc..c1972dd51 100644 --- a/MCGalaxy/Commands/Bots/CmdBot.cs +++ b/MCGalaxy/Commands/Bots/CmdBot.cs @@ -83,7 +83,8 @@ namespace MCGalaxy.Commands.Bots { } if (botName.CaselessEq("all")) { - PlayerBot.RemoveAllFromLevel(p.level); return; + PlayerBot.RemoveLoadedBots(p.level, false); + BotsFile.Save(p.level); } else { PlayerBot bot = Matcher.FindBots(p, botName); if (bot == null) return; diff --git a/MCGalaxy/Levels/Level.Fields.cs b/MCGalaxy/Levels/Level.Fields.cs index 11f1fa851..3c9ae89cb 100644 --- a/MCGalaxy/Levels/Level.Fields.cs +++ b/MCGalaxy/Levels/Level.Fields.cs @@ -44,6 +44,7 @@ namespace MCGalaxy { internal readonly object PropsLock = new object(); public ExtrasCollection Extras = new ExtrasCollection(); public VolatileArray Bots = new VolatileArray(false); + bool unloadedBots; internal HandleDelete[] deleteHandlers = new HandleDelete[Block.Count * 2]; internal HandlePlace[] placeHandlers = new HandlePlace[Block.Count * 2]; diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs index e29356cf3..3fc7fc202 100644 --- a/MCGalaxy/Levels/Level.cs +++ b/MCGalaxy/Levels/Level.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using MCGalaxy.Blocks; +using MCGalaxy.Bots; using MCGalaxy.Commands; using MCGalaxy.DB; using MCGalaxy.Events.LevelEvents; @@ -176,7 +177,12 @@ namespace MCGalaxy { LevelInfo.Loaded.Remove(this); try { - PlayerBot.UnloadFromLevel(this); + if (!unloadedBots) { + unloadedBots = true; + BotsFile.Save(this); + PlayerBot.RemoveLoadedBots(this, false); + } + physThread.Abort(); physThread.Join(); } catch {