Search in sources :

Example 1 with RandomStatePattern

use of com.sk89q.worldedit.function.pattern.RandomStatePattern in project FastAsyncWorldEdit by IntellectualSites.

the class RandomStatePatternParser method parseFromInput.

@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
    if (!input.startsWith("*")) {
        return null;
    }
    boolean wasFuzzy = context.isPreferringWildcard();
    context.setPreferringWildcard(true);
    BaseBlock block = worldEdit.getBlockFactory().parseFromInput(input.substring(1), context);
    context.setPreferringWildcard(wasFuzzy);
    if (block.getStates().size() == block.getBlockType().getPropertyMap().size()) {
        // they requested random with *, but didn't leave any states empty - simplify
        return block;
    } else if (block.toImmutableState() instanceof FuzzyBlockState) {
        return new RandomStatePattern((FuzzyBlockState) block.toImmutableState());
    } else {
        // only should happen if parseLogic changes
        return null;
    }
}
Also used : RandomStatePattern(com.sk89q.worldedit.function.pattern.RandomStatePattern) FuzzyBlockState(com.sk89q.worldedit.world.block.FuzzyBlockState) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Aggregations

RandomStatePattern (com.sk89q.worldedit.function.pattern.RandomStatePattern)1 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)1 FuzzyBlockState (com.sk89q.worldedit.world.block.FuzzyBlockState)1