fCraft.BuildingCommands.DoorAdd C# (CSharp) Method

DoorAdd() private static method

private static DoorAdd ( Player player, Vector3I marks, object tag ) : void
player Player
marks Vector3I
tag object
return void
        private static void DoorAdd( Player player, Vector3I[] marks, object tag )
        {
            int sx = Math.Min( marks[0].X, marks[1].X );
            int ex = Math.Max( marks[0].X, marks[1].X );
            int sy = Math.Min( marks[0].Y, marks[1].Y );
            int ey = Math.Max( marks[0].Y, marks[1].Y );
            int sz = Math.Min( marks[0].Z, marks[1].Z );
            int ez = Math.Max( marks[0].Z, marks[1].Z );

            int volume = ( ex - sx + 1 ) * ( ey - sy + 1 ) * ( ez - sz + 1 );
            if ( volume > 30 ) {
                player.Message( "Doors are only allowed to be {0} blocks", 30 );
                return;
            }
            if ( !player.Info.Rank.AllowSecurityCircumvention ) {
                SecurityCheckResult buildCheck = player.World.BuildSecurity.CheckDetailed( player.Info );
                switch ( buildCheck ) {
                    case SecurityCheckResult.BlackListed:
                        player.Message( "Cannot add a door to world {0}&S: You are barred from building here.",
                                        player.World.ClassyName );
                        return;

                    case SecurityCheckResult.RankTooLow:
                        player.Message( "Cannot add a door to world {0}&S: You are not allowed to build here.",
                                        player.World.ClassyName );
                        return;
                    //case SecurityCheckResult.RankTooHigh:
                }
            }
            List<Vector3I> blocks = new List<Vector3I>();
            for ( int x = sx; x < ex; x++ ) {
                for ( int y = sy; y < ey; y++ ) {
                    for ( int z = sz; z < ez; z++ ) {
                        if ( player.CanPlace( player.World.Map, new Vector3I( x, y, z ), Block.Wood, BlockChangeContext.Manual ) != CanPlaceResult.Allowed ) {
                            player.Message( "Cannot add a door to world {0}&S: Build permissions in this area replied with 'denied'.",
                                        player.World.ClassyName );
                            return;
                        }
                        blocks.Add( new Vector3I( x, y, z ) );
                    }
                }
            }
            if (player.World != null)
            {
                var door = new Door( player.World.Name,
                    blocks.ToArray(),
                    fCraft.Doors.Door.GenerateName( player.World ),
                    player.ClassyName );
                door.Range = new DoorRange( sx, ex, sy, ey, sz, ez );
                if (DoorHandler.GetInstance().GetAffectedBlocks( door ).Any(v => DoorHandler.GetInstance().GetDoor( player.World, v ) != null))
                {
                    player.Message( "You can not build a door inside a door, U MAD BRO?" );
                    if (player.World != null) player.World.Map.DoorID--;
                    return;
                }
                DoorHandler.CreateDoor( door, player.World );
                Logger.Log( LogType.UserActivity, "{0} created door {1} (on world {2})", player.Name, door.Name, player.World.Name );
                player.Message( "Door created on world {0}&S with name {1}", player.World.ClassyName, door.Name );
            }
        }