mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Fix doing /unload on a level causing bots to be lost, fixes #489.
This commit is contained in:
parent
86f3449889
commit
05e6e14c49
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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];
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user