SaveMap() public method

public SaveMap ( ) : void
return void
Exemplo n.º 1
0
        internal static void ReplaceWorld([NotNull] World oldWorld, [NotNull] World newWorld)
        {
            if (oldWorld == null)
            {
                throw new ArgumentNullException("oldWorld");
            }
            if (newWorld == null)
            {
                throw new ArgumentNullException("newWorld");
            }

            lock ( SyncRoot ) {
                if (oldWorld == newWorld)
                {
                    throw new WorldOpException(oldWorld.Name, WorldOpExceptionCode.NoChangeNeeded);
                }

                if (!WorldIndex.ContainsValue(oldWorld))
                {
                    throw new WorldOpException(oldWorld.Name, WorldOpExceptionCode.WorldNotFound);
                }

                if (WorldIndex.ContainsValue(newWorld))
                {
                    throw new InvalidOperationException("New world already exists on the list.");
                }

                // cycle load/unload on the new world to save it under the new name
                newWorld.Name = oldWorld.Name;
                if (newWorld.Preload)
                {
                    newWorld.SaveMap();
                }
                else
                {
                    newWorld.UnloadMap(false);
                }

                WorldIndex[oldWorld.Name.ToLower()] = newWorld;
                oldWorld.Map = null;

                // change the main worlds, if needed
                if (oldWorld == MainWorld)
                {
                    MainWorld = newWorld;
                }
                foreach (Rank rank in RankManager.Ranks)
                {
                    if (rank.MainWorld == oldWorld)
                    {
                        rank.MainWorld = newWorld;
                    }
                }

                SaveWorldList();
                UpdateWorldList();
            }
        }
Exemplo n.º 2
0
        public static World AddWorld([CanBeNull] Player player, [NotNull] string name, [CanBeNull] Map map,
                                     bool neverUnload)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (!World.IsValidName(name))
            {
                throw new WorldOpException(name, WorldOpExceptionCode.InvalidWorldName);
            }

            lock (SyncRoot)
            {
                if (WorldIndex.ContainsKey(name.ToLower()))
                {
                    throw new WorldOpException(name, WorldOpExceptionCode.DuplicateWorldName);
                }

                if (RaiseWorldCreatingEvent(player, name, map))
                {
                    throw new WorldOpException(name, WorldOpExceptionCode.Cancelled);
                }

                World newWorld = new World(name)
                {
                    Map = map
                };

                if (neverUnload)
                {
                    newWorld.NeverUnload = true;
                }

                if (map != null)
                {
                    newWorld.SaveMap();
                }

                WorldIndex.Add(name.ToLower(), newWorld);
                UpdateWorldList();

                RaiseWorldCreatedEvent(player, newWorld);

                return(newWorld);
            }
        }
Exemplo n.º 3
0
        public static World AddWorld( [CanBeNull] Player player, [NotNull] string name, [CanBeNull] Map map, bool preload ) {
            if( name == null ) throw new ArgumentNullException( "name" );

            if( !World.IsValidName( name ) ) {
                throw new WorldOpException( name, WorldOpExceptionCode.InvalidWorldName );
            }

            lock( SyncRoot ) {
                if( WorldIndex.ContainsKey( name.ToLower() ) ) {
                    throw new WorldOpException( name, WorldOpExceptionCode.DuplicateWorldName );
                }

                if( RaiseWorldCreatingEvent( player, name, map ) ) {
                    throw new WorldOpException( name, WorldOpExceptionCode.Cancelled );
                }

                World newWorld = new World( name ) {
                    Map = map
                };

                if( preload ) {
                    newWorld.Preload = true;
                }

                if( map != null ) {
                    newWorld.SaveMap();
                }

                WorldIndex.Add( name.ToLower(), newWorld );
                UpdateWorldList();

                RaiseWorldCreatedEvent( player, newWorld );

                return newWorld;
            }
        }
Exemplo n.º 4
0
        public static World AddWorld( string name, Map map, bool neverUnload )
        {
            lock( worldListLock ) {
                if( worlds.ContainsKey( name ) ) return null;
                if( !Player.IsValidName( name ) ) return null;
                World newWorld = new World( name );
                newWorld.neverUnload = neverUnload;

                if( map != null ) {
                    // if a map is given
                    newWorld.map = map;
                    if( !neverUnload ) {
                        newWorld.UnloadMap();// UnloadMap also saves the map
                    } else {
                        newWorld.SaveMap( null );
                    }

                } else {
                    // generate default map
                    if( neverUnload ) newWorld.LoadMap();
                }
                worlds.Add( name, newWorld );

                newWorld.updateTaskId = AddTask( UpdateBlocks, Config.GetInt( ConfigKey.TickInterval ), newWorld );

                if( Config.GetInt( ConfigKey.SaveInterval ) > 0 ) {
                    int saveInterval = Config.GetInt( ConfigKey.SaveInterval ) * 1000;
                    newWorld.saveTaskId = AddTask( SaveMap, saveInterval, newWorld, saveInterval );
                }

                if( Config.GetInt( ConfigKey.BackupInterval ) > 0 ) {
                    int backupInterval = Config.GetInt( ConfigKey.BackupInterval ) * 1000 * 60;
                    newWorld.backupTaskId = AddTask( AutoBackup, backupInterval, newWorld, (Config.GetBool( ConfigKey.BackupOnStartup ) ? 0 : backupInterval) );
                }

                newWorld.UpdatePlayerList();

                return newWorld;
            }
        }