mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -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);
|
if (save) BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UnloadFromLevel(Level lvl) {
|
internal static void RemoveLoadedBots(Level lvl, bool save) {
|
||||||
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) {
|
|
||||||
PlayerBot[] bots = lvl.Bots.Items;
|
PlayerBot[] bots = lvl.Bots.Items;
|
||||||
for (int i = 0; i < bots.Length; i++) {
|
for (int i = 0; i < bots.Length; i++) {
|
||||||
Remove(bots[i], save);
|
Remove(bots[i], save);
|
||||||
|
@ -83,7 +83,8 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (botName.CaselessEq("all")) {
|
if (botName.CaselessEq("all")) {
|
||||||
PlayerBot.RemoveAllFromLevel(p.level); return;
|
PlayerBot.RemoveLoadedBots(p.level, false);
|
||||||
|
BotsFile.Save(p.level);
|
||||||
} else {
|
} else {
|
||||||
PlayerBot bot = Matcher.FindBots(p, botName);
|
PlayerBot bot = Matcher.FindBots(p, botName);
|
||||||
if (bot == null) return;
|
if (bot == null) return;
|
||||||
|
@ -44,6 +44,7 @@ namespace MCGalaxy {
|
|||||||
internal readonly object PropsLock = new object();
|
internal readonly object PropsLock = new object();
|
||||||
public ExtrasCollection Extras = new ExtrasCollection();
|
public ExtrasCollection Extras = new ExtrasCollection();
|
||||||
public VolatileArray<PlayerBot> Bots = new VolatileArray<PlayerBot>(false);
|
public VolatileArray<PlayerBot> Bots = new VolatileArray<PlayerBot>(false);
|
||||||
|
bool unloadedBots;
|
||||||
|
|
||||||
internal HandleDelete[] deleteHandlers = new HandleDelete[Block.Count * 2];
|
internal HandleDelete[] deleteHandlers = new HandleDelete[Block.Count * 2];
|
||||||
internal HandlePlace[] placeHandlers = new HandlePlace[Block.Count * 2];
|
internal HandlePlace[] placeHandlers = new HandlePlace[Block.Count * 2];
|
||||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using MCGalaxy.Blocks;
|
using MCGalaxy.Blocks;
|
||||||
|
using MCGalaxy.Bots;
|
||||||
using MCGalaxy.Commands;
|
using MCGalaxy.Commands;
|
||||||
using MCGalaxy.DB;
|
using MCGalaxy.DB;
|
||||||
using MCGalaxy.Events.LevelEvents;
|
using MCGalaxy.Events.LevelEvents;
|
||||||
@ -176,7 +177,12 @@ namespace MCGalaxy {
|
|||||||
LevelInfo.Loaded.Remove(this);
|
LevelInfo.Loaded.Remove(this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PlayerBot.UnloadFromLevel(this);
|
if (!unloadedBots) {
|
||||||
|
unloadedBots = true;
|
||||||
|
BotsFile.Save(this);
|
||||||
|
PlayerBot.RemoveLoadedBots(this, false);
|
||||||
|
}
|
||||||
|
|
||||||
physThread.Abort();
|
physThread.Abort();
|
||||||
physThread.Join();
|
physThread.Join();
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user