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(); }
/// <summary> Renames the given map and associated metadata. Does not unload. </summary> /// <remarks> Backups are NOT renamed. </remarks> public static bool Rename(Player p, string src, string dst) { if (LevelInfo.MapExists(dst)) { p.Message("&WLevel \"{0}\" already exists.", dst); return(false); } Level lvl = LevelInfo.FindExact(src); if (lvl == Server.mainLevel) { p.Message("Cannot rename the main level."); return(false); } List <Player> players = null; if (lvl != null) { players = lvl.getPlayers(); } if (lvl != null && !lvl.Unload()) { p.Message("Unable to rename the level, because it could not be unloaded. " + "A game may currently be running on it."); return(false); } File.Move(LevelInfo.MapPath(src), LevelInfo.MapPath(dst)); DoAll(src, dst, action_move); // TODO: Should we move backups still try { //MoveBackups(src, dst); } catch { } RenameDatabaseTables(p, src, dst); BlockDBFile.MoveBackingFile(src, dst); OnLevelRenamedEvent.Call(src, dst); if (players == null) { return(true); } // Move all the old players to the renamed map Load(p, dst, false); foreach (Player pl in players) { PlayerActions.ChangeMap(pl, dst); } 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); }