fCraft.CommandReader.NextBlockWithParam C# (CSharp) Метод

NextBlockWithParam() публичный Метод

Parses next parameter as a Minecraft block name. Allows an optional integer parameter to follow the block name after a slash, e.g. "BlockName/#" Messages warnings directly to the player in case of problems.
public NextBlockWithParam ( [ player, bool allowNoneBlock, Block &block, int &param ) : bool
player [ Player to send warnings to (if any come up).
allowNoneBlock bool Whether "none"/"skip" blocktype is allowed.
block Block On success, this is set to the given block type. /// On failure, this is set to Block.None
param int Optional integer parameter. Set to 1 if not given.
Результат bool
        public bool NextBlockWithParam( [CanBeNull] Player player, bool allowNoneBlock, out Block block, out int param ) {
            block = Block.None;
            param = 1;

            string jointString = Next();
            if( jointString == null ) {
                return false;
            }

            int slashIndex = jointString.IndexOf( '/' );
            if( slashIndex != -1 ) {
                string blockName = jointString.Substring( 0, slashIndex );
                string paramString = jointString.Substring( slashIndex + 1 );

                if( Map.GetBlockByName( blockName, true, out block ) ) {
                    if( block == Block.None && !allowNoneBlock ) {
                        if( player != null ) {
                            player.Message( "The \"none\" block is not allowed here" );
                        }
                    } else if( Int32.TryParse( paramString, out param ) ) {
                        return true;
                    } else if( player != null ) {
                        player.Message( "Could not parse \"{0}\" as an integer.", paramString );
                    }
                } else if( player != null ) {
                    player.Message( "Unrecognized blocktype \"{0}\"", blockName );
                }

            } else {
                if( Map.GetBlockByName( jointString, true, out block ) ) {
                    if( block != Block.None || allowNoneBlock ) {
                        return true;
                    } else if( player != null ) {
                        player.Message( "The \"none\" block is not allowed here" );
                    }
                } else if( player != null ) {
                    player.Message( "Unrecognized blocktype \"{0}\"", jointString );
                }
            }
            return false;
        }