public override void Load(bool startup) { Command.Register(new CmdReloadEffects()); Command.Register(new CmdEffect()); Command.Register(new CmdSpawner()); rnd = new Random(); LoadEffects(); DefineEffectsAll(); playerEffects = PlayerExtList.Load("extra/playereffects.txt"); OnPlayerMoveEvent.Register(OnPlayerMove, Priority.Low); OnPlayerFinishConnectingEvent.Register(OnPlayerFinishConnecting, Priority.Low); OnLevelLoadedEvent.Register(OnLevelLoaded, Priority.Low); OnLevelUnloadEvent.Register(OnLevelUnload, Priority.Low); OnLevelDeletedEvent.Register(OnLevelDeleted, Priority.Low); OnLevelCopiedEvent.Register(OnLevelCopied, Priority.Low); OnLevelRenamedEvent.Register(OnLevelRenamed, Priority.Low); SpawnersFile.cache = new ThreadSafeCache(); if (!Directory.Exists(SpawnersFile.spawnerDirectory)) { Directory.CreateDirectory(SpawnersFile.spawnerDirectory); } Level[] levels = LevelInfo.Loaded.Items; foreach (Level level in levels) { SpawnersFile.Load(level); } spawnerAccum = 0; ActivateSpawners(); }
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 override void Unload(bool shutdown) { Command.Unregister(Command.Find("ReloadEffects")); Command.Unregister(Command.Find("Effect")); Command.Unregister(Command.Find("Spawner")); OnPlayerFinishConnectingEvent.Unregister(OnPlayerFinishConnecting); OnLevelLoadedEvent.Unregister(OnLevelLoaded); OnLevelUnloadEvent.Unregister(OnLevelUnload); OnLevelDeletedEvent.Unregister(OnLevelDeleted); OnLevelCopiedEvent.Unregister(OnLevelCopied); OnLevelRenamedEvent.Unregister(OnLevelRenamed); spawnersAtLevel.Clear(); instance.Cancel(tickSpawners); }
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); }