Exemplo n.º 1
0
        public ReadResults Parse(IStringReader reader, DispatcherResources resources, out EntitySelector result)
        {
            int start = reader.GetCursor();
            EntitySelectorParser entitySelectorParser = new EntitySelectorParser(reader, resources, UseBedrock);
            ReadResults          readResults          = entitySelectorParser.Parse(out result);

            if (!readResults.Successful)
            {
                return(readResults);
            }

            if (result.MaxResults > 1 && SingleEntity)
            {
                reader.SetCursor(start);
                if (PlayersOnly)
                {
                    return(ReadResults.Failure(CommandError.SelectorTooManyPlayers().WithContext(reader)));
                }
                else
                {
                    return(ReadResults.Failure(CommandError.SelectorTooManyEntities().WithContext(reader)));
                }
            }
            if (result.IncludesEntities && PlayersOnly && !result.IsSelf)
            {
                reader.SetCursor(start);
                return(ReadResults.Failure(CommandError.SelectorPlayersOnly().WithContext(reader)));
            }

            return(ReadResults.Success());
        }
        public ReadResults Parse(IStringReader reader, DispatcherResources resources, out ScoreHolder result)
        {
            result = default;

            if (reader.CanRead() && reader.Peek() == '@')
            {
                EntitySelectorParser entitySelectorParser = new EntitySelectorParser(reader, resources, UseBedrock);
                ReadResults          readResults          = entitySelectorParser.Parse(out EntitySelector entitySelector);
                if (!readResults.Successful)
                {
                    return(readResults);
                }
                if (!Multiple && entitySelector.MaxResults > 1)
                {
                    return(ReadResults.Failure(CommandError.SelectorTooManyEntities()));
                }
                result = new ScoreHolder(null, entitySelector);
                return(ReadResults.Success());
            }

            if (UseBedrock)
            {
                ReadResults readResults = reader.ReadString(out string name);
                if (!readResults.Successful)
                {
                    return(readResults);
                }

                result = new ScoreHolder(name, null);
                return(ReadResults.Success());
            }
            else
            {
                int start = reader.GetCursor();
                while (!reader.AtEndOfArgument())
                {
                    reader.Skip();
                }
                string name = reader.GetString()[start..reader.GetCursor()];