fCraft.BuildingCommands.TreeHandler C# (CSharp) Method

TreeHandler() private static method

private static TreeHandler ( Player player, Command cmd ) : void
player Player
cmd Command
return void
        private static void TreeHandler( Player player, Command cmd )
        {
            string shapeName = cmd.Next();
            int height;
            Forester.TreeShape shape;

            // that's one ugly if statement... does the job though.
            if ( shapeName == null ||
                !cmd.NextInt( out height ) ||
                !EnumUtil.TryParse( shapeName, out shape, true ) ||
                shape == Forester.TreeShape.Stickly ||
                shape == Forester.TreeShape.Procedural ) {
                CdTree.PrintUsage( player );
                player.Message( "Available shapes: Normal, Bamboo, Palm, Cone, Round, Rainforest, Mangrove." );
                return;
            }

            if ( height < 6 || height > 1024 ) {
                player.Message( "Tree height must be 6 blocks or above" );
                return;
            }
            int volume = ( int )Math.Pow( height, 3 );
            if ( !player.CanDraw( volume ) ) {
                player.Message( String.Format( "You are only allowed to run commands that affect up to {0} blocks. This one would affect {1} blocks.",
                                               player.Info.Rank.DrawLimit, volume ) );
                return;
            }

            Map map = player.World.Map;

            ForesterArgs args = new ForesterArgs {
                Height = height - 1,
                Operation = Forester.ForesterOperation.Add,
                Map = map,
                Shape = shape,
                TreeCount = 1,
                RootButtresses = false,
                Roots = Forester.RootMode.None,
                Rand = new Random()
            };
            player.SelectionStart( 1, TreeCallback, args, CdTree.Permissions );
            player.MessageNow( "Tree: Place a block or type /Mark to use your location." );
        }