fCraft.WorldManager.AddWorld C# (CSharp) Method

AddWorld() public static method

public static AddWorld ( [ player, [ name, [ map, bool neverUnload ) : World
player [
name [
map [
neverUnload bool
return World
        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;
            }
        }

Usage Example

Example #1
0
        public static void Start(Player player)
        {
            Map map = MapGeneratorOld.GenerateEmpty(64, 128, 16);

            map.Save("maps/minefield.fcm");
            if (_world != null)
            {
                WorldManager.RemoveWorld(_world);
            }
            WorldManager.AddWorld(Player.Console, "Minefield", map, true);
            _map   = map;
            _world = WorldManager.FindWorldExact("Minefield");
            SetUpRed();
            SetUpMiddleWater();
            SetUpGreen();
            SetUpMines();
            _map.Spawn = new Position(_map.Width / 2, 5, _ground + 3).ToVector3I().ToPlayerCoords();
            _world.LoadMap();
            _world.gameMode = GameMode.MineField;
            _world.EnableTNTPhysics(Player.Console, false);
            Server.Message("{0}&S started a game of MineField on world Minefield!", player.ClassyName);
            WorldManager.SaveWorldList();
            Server.RequestGC();
        }
All Usage Examples Of fCraft.WorldManager::AddWorld