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

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

Reads a token and gets an "on" (1) or "off" (0) input from command.
public NextOnOff ( bool &param ) : bool
param bool if user gave "on" or "1", this is set to true. /// Otherwise (if "off" or "0" is given, if nothing was given, /// or if an unrecognized string was given) this is set to false.
Результат bool
        public bool NextOnOff( out bool param ) {
            string token = Next();
            if( token == null ) {
                // nothing given
                param = false;
                return false;
            } else if( token.Equals( "on", StringComparison.OrdinalIgnoreCase ) || token == "1" ) {
                // "on" or "1" given
                param = true;
            } else if( token.Equals( "off", StringComparison.OrdinalIgnoreCase ) || token == "0" ) {
                // "off" or "0" given
                param = false;
            } else {
                // unrecognized string given
                param = false;
            }
            return true;
        }

Usage Example

Пример #1
0
        static void WaterHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnWaterOn = (player.GetBind(Block.Aqua) != Block.Water ||
                                player.GetBind(Block.Cyan) != Block.Water ||
                                player.GetBind(Block.Blue) != Block.Water);

            if (cmd.HasNext && !cmd.NextOnOff(out turnWaterOn))
            {
                CdWater.PrintUsage(player);
                return;
            }

            if (turnWaterOn)
            {
                player.Bind(Block.Aqua, Block.Water);
                player.Bind(Block.Cyan, Block.Water);
                player.Bind(Block.Blue, Block.Water);
                player.Message("Water: ON. Blue blocks are replaced with water.");
            }
            else
            {
                player.ResetBind(Block.Aqua, Block.Cyan, Block.Blue);
                player.Message("Water: OFF");
            }
        }
All Usage Examples Of fCraft.CommandReader::NextOnOff