All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.placeblock.commandapi.core.parameter.BooleanParameter Maven / Gradle / Ivy

package de.placeblock.commandapi.core.parameter;

import de.placeblock.commandapi.core.SuggestionBuilder;
import de.placeblock.commandapi.core.exception.CommandParseException;
import de.placeblock.commandapi.core.parser.ParsedCommandBranch;

import java.util.List;

/**
 * Author: Placeblock
 */
public class BooleanParameter implements Parameter{
    public static  BooleanParameter bool() {
        return new BooleanParameter<>();
    }

    @Override
    public Boolean parse(ParsedCommandBranch command, S source) throws CommandParseException {
        return command.getReader().readBoolean();
    }

    @Override
    public void getSuggestions(SuggestionBuilder suggestionBuilder) {
        String partial = suggestionBuilder.getRemaining();
        suggestionBuilder.withSuggestions(Parameter.startsWith(List.of("true", "false"), partial));
    }
}