public bool Unload(bool silent = false, bool save = true) { if (Server.mainLevel == this) { return(false); } // Still cleanup resources, even if this is not a true level if (IsMuseum) { Cleanup(); return(true); } bool cancel = false; OnLevelUnloadEvent.Call(this, ref cancel); if (cancel) { Logger.Log(LogType.SystemActivity, "Unload canceled by Plugin! (Map: {0})", name); return(false); } MovePlayersToMain(); if (save && SaveChanges && Changed) { Save(); } if (save && SaveChanges) { SaveBlockDBChanges(); } MovePlayersToMain(); LevelInfo.Remove(this); try { if (!unloadedBots) { unloadedBots = true; BotsFile.Save(this); PlayerBot.RemoveLoadedBots(this, false); } } catch (Exception ex) { Logger.LogError("Error saving bots", ex); } Cleanup(); if (!silent) { Chat.MessageOps(ColoredName + " &Swas unloaded."); } Logger.Log(LogType.SystemActivity, name + " was unloaded."); return(true); }
public bool Unload(bool silent = false, bool save = true) { if (Server.mainLevel == this || IsMuseum) { return(false); } OnLevelUnloadEvent.Call(this); if (cancelunload) { Logger.Log(LogType.SystemActivity, "Unload canceled by Plugin! (Map: {0})", name); cancelunload = false; return(false); } MovePlayersToMain(); if (save && SaveChanges && Changed) { Save(false, true); } if (save && SaveChanges) { SaveBlockDBChanges(); } MovePlayersToMain(); LevelInfo.Remove(this); try { if (!unloadedBots) { unloadedBots = true; BotsFile.Save(this); PlayerBot.RemoveLoadedBots(this, false); } } catch (Exception ex) { Logger.LogError("Error saving bots", ex); } try { physThread.Abort(); physThread.Join(); } catch { } Dispose(); Server.DoGC(); if (!silent) { Chat.MessageOps(ColoredName + " %Swas unloaded."); } Logger.Log(LogType.SystemActivity, name + " was unloaded."); return(true); }
public bool Unload(bool silent = false, bool save = true) { if (Server.mainLevel == this || IsMuseum) { return(false); } if (Server.lava.active && Server.lava.map == this) { return(false); } OnLevelUnloadEvent.Call(this); if (cancelunload) { Logger.Log(LogType.SystemActivity, "Unload canceled by Plugin! (Map: {0})", name); cancelunload = false; return(false); } MovePlayersToMain(); if (save && Changed && ShouldSaveChanges()) { Save(false, true); } if (save && ShouldSaveChanges()) { SaveBlockDBChanges(); } if (TntWarsGame.Find(this) != null) { foreach (TntWarsGame.player pl in TntWarsGame.Find(this).Players) { pl.p.CurrentTntGameNumber = -1; Player.Message(pl.p, "TNT Wars: The TNT Wars game you are currently playing has been deleted!"); pl.p.PlayingTntWars = false; pl.p.canBuild = true; TntWarsGame.SetTitlesAndColor(pl, true); } Logger.Log(LogType.GameActivity, "TNT Wars: Game deleted on " + name); TntWarsGame.GameList.Remove(TntWarsGame.Find(this)); } MovePlayersToMain(); LevelInfo.Loaded.Remove(this); try { if (!unloadedBots) { unloadedBots = true; BotsFile.Save(this); PlayerBot.RemoveLoadedBots(this, false); } physThread.Abort(); physThread.Join(); } catch { } finally { Dispose(); Server.DoGC(); if (!silent) { Chat.MessageOps(ColoredName + " %Swas unloaded."); } Logger.Log(LogType.SystemActivity, name + " was unloaded."); } return(true); }
public bool Unload(bool silent = false, bool save = true) { if (Server.mainLevel == this || IsMuseum) { return(false); } if (Server.lava.active && Server.lava.map == this) { return(false); } if (LevelUnload != null) { LevelUnload(this); } OnLevelUnloadEvent.Call(this); if (cancelunload) { Server.s.Log("Unload canceled by Plugin! (Map: " + name + ")"); cancelunload = false; return(false); } MovePlayersToMain(); if (changed && ShouldSaveChanges()) { Save(false, true); saveChanges(); } if (TntWarsGame.Find(this) != null) { foreach (TntWarsGame.player pl in TntWarsGame.Find(this).Players) { pl.p.CurrentTntGameNumber = -1; Player.SendMessage(pl.p, "TNT Wars: The TNT Wars game you are currently playing has been deleted!"); pl.p.PlayingTntWars = false; pl.p.canBuild = true; TntWarsGame.SetTitlesAndColor(pl, true); } Server.s.Log("TNT Wars: Game deleted on " + name); TntWarsGame.GameList.Remove(TntWarsGame.Find(this)); } MovePlayersToMain(); LevelInfo.Loaded.Remove(this); try { PlayerBot.RemoveAllFromLevel(this); //physChecker.Stop(); //physChecker.Dispose(); physThread.Abort(); physThread.Join(); } catch { } finally { Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); if (!silent) { Chat.GlobalMessageOps("&3" + name + Server.DefaultColor + " was unloaded."); } Server.s.Log(string.Format("{0} was unloaded.", name)); } return(true); }