Fix doing /unload on a level causing bots to be lost, fixes #489.

This commit is contained in:
UnknownShadow200 2017-09-05 11:12:00 +10:00
parent 86f3449889
commit 05e6e14c49
4 changed files with 11 additions and 13 deletions

View File

@ -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);

View File

@ -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;

View File

@ -44,6 +44,7 @@ namespace MCGalaxy {
internal readonly object PropsLock = new object();
public ExtrasCollection Extras = new ExtrasCollection();
public VolatileArray<PlayerBot> Bots = new VolatileArray<PlayerBot>(false);
bool unloadedBots;
internal HandleDelete[] deleteHandlers = new HandleDelete[Block.Count * 2];
internal HandlePlace[] placeHandlers = new HandlePlace[Block.Count * 2];

View File

@ -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 {