Beispiel #1
0
        public static void Replace(Level old, Level lvl)
        {
            LevelDB.SaveBlockDB(old);
            LevelInfo.Remove(old);
            LevelInfo.Add(lvl);

            old.SetPhysics(0);
            old.ClearPhysics();
            lvl.StartPhysics();

            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (pl.level != old)
                {
                    continue;
                }
                pl.level = lvl;
                ReloadFor(Player.Console, pl, false);
            }

            old.Unload(true, false);
            if (old == Server.mainLevel)
            {
                Server.mainLevel = lvl;
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }