Example #1
0
        public World ChangeMap([NotNull] Map newMap)
        {
            if (newMap == null)
            {
                throw new ArgumentNullException("newMap");
            }
            lock ( SyncRoot ) {
                World newWorld = new World(Name)
                {
                    AccessSecurity = (SecurityController)AccessSecurity.Clone(),
                    BuildSecurity  = (SecurityController)BuildSecurity.Clone(),
                    IsHidden       = IsHidden,
                    BlockDB        = BlockDB,
                    lastBackup     = lastBackup,
                    BackupInterval = BackupInterval,
                    IsLocked       = IsLocked,
                    LockedBy       = LockedBy,
                    UnlockedBy     = UnlockedBy,
                    LockedOn       = LockedOn,
                    UnlockedOn     = UnlockedOn,
                    LoadedBy       = LoadedBy,
                    LoadedOn       = LoadedOn,
                    MapChangedBy   = MapChangedBy,
                    MapChangedOn   = DateTime.UtcNow,
                    Buildable      = Buildable,
                    Deletable      = Deletable,
                };
                newWorld.CopyENV(this);
                WorldManager.ParseCPEMetaData(ref newWorld, newMap, Name);
                newMap.World     = newWorld;
                newWorld.Map     = newMap;
                newWorld.Preload = preload;
                WorldManager.ReplaceWorld(this, newWorld);
                using (BlockDB.GetWriteLock()) {
                    BlockDB.Clear();
                    BlockDB.World = newWorld;
                }

                foreach (Player player in Players)
                {
                    player.JoinWorld(newWorld, WorldChangeReason.Rejoin);
                }
                return(newWorld);
            }
        }