Java Code Examples for com.mojang.brigadier.StringReader#readInt()

The following examples show how to use com.mojang.brigadier.StringReader#readInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XPArgumentType.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public Integer parse(StringReader reader) throws CommandSyntaxException {
    int amount = reader.readInt();
    if (reader.canRead() && (reader.peek() == 'l' || reader.peek() == 'L'))
        reader.skip();
    return amount;
}
 
Example 2
Source File: IntegerArgumentType.java    From brigadier with MIT License 5 votes vote down vote up
@Override
public Integer parse(final StringReader reader) throws CommandSyntaxException {
    final int start = reader.getCursor();
    final int result = reader.readInt();
    if (result < minimum) {
        reader.setCursor(start);
        throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.integerTooLow().createWithContext(reader, result, minimum);
    }
    if (result > maximum) {
        reader.setCursor(start);
        throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.integerTooHigh().createWithContext(reader, result, maximum);
    }
    return result;
}
 
Example 3
Source File: BlockStateArgumentType_1_12_2.java    From multiconnect with MIT License 4 votes vote down vote up
@Override
public Custom_1_12_Argument parse(StringReader reader) throws CommandSyntaxException {
    List<ParsedArgument<?, ?>> result = new ArrayList<>();

    int start = reader.getCursor();
    Identifier id = Identifier.fromCommandInput(reader);
    if (!Registry.BLOCK.containsId(id)) {
        reader.setCursor(start);
        throw BlockArgumentParser.INVALID_BLOCK_ID_EXCEPTION.createWithContext(reader, id);
    }
    Block block = Registry.BLOCK.get(id);
    if (!isValidBlock(block)) {
        reader.setCursor(start);
        throw BlockArgumentParser.INVALID_BLOCK_ID_EXCEPTION.createWithContext(reader, id);
    }

    result.add(new ParsedArgument<>(start, reader.getCursor(), block));
    if (!reader.canRead())
        return new Custom_1_12_Argument(result);

    reader.expect(' ');
    start = reader.getCursor();
    try {
        int meta;
        if (!test && reader.peek() == '*') {
            reader.skip();
            meta = -1;
        } else {
            meta = reader.readInt();
        }
        if (meta >= (test ? -1 : 0) && meta < 16 && (!reader.canRead() || reader.peek() == ' ')) {
            result.add(new ParsedArgument<>(start, reader.getCursor(), meta));
            return new Custom_1_12_Argument(result);
        }
    } catch (CommandSyntaxException ignore) {
    }
    reader.setCursor(start);
    if ("default".equals(reader.readUnquotedString())) {
        result.add(new ParsedArgument<>(start, reader.getCursor(), 0));
        return new Custom_1_12_Argument(result);
    }

    reader.setCursor(start);

    List<String> properties = BlockStateReverseFlattening.OLD_PROPERTIES.getOrDefault(id, Collections.emptyList());
    Set<String> alreadySeen = new HashSet<>();
    while (reader.canRead() && reader.peek() != ' ') {
        int propStart = reader.getCursor();
        String property = reader.readUnquotedString();
        if (alreadySeen.contains(property)) {
            reader.setCursor(propStart);
            throw BlockArgumentParser.DUPLICATE_PROPERTY_EXCEPTION.createWithContext(reader, id, property);
        }
        if (!properties.contains(property)) {
            reader.setCursor(propStart);
            throw BlockArgumentParser.UNKNOWN_PROPERTY_EXCEPTION.createWithContext(reader, id, property);
        }
        alreadySeen.add(property);
        reader.expect('=');
        int valueStart = reader.getCursor();
        String value = reader.readUnquotedString();
        if (!BlockStateReverseFlattening.OLD_PROPERTY_VALUES.get(Pair.of(id, property)).contains(value)) {
            reader.setCursor(valueStart);
            throw BlockArgumentParser.INVALID_PROPERTY_EXCEPTION.createWithContext(reader, id, property, value);
        }
        if (reader.canRead() && reader.peek() != ' ')
            reader.expect(',');
    }

    result.add(new ParsedArgument<>(start, reader.getCursor(), null));
    return new Custom_1_12_Argument(result);
}