Search in sources :

Example 1 with BlockCategory

use of com.sk89q.worldedit.world.block.BlockCategory in project PlotSquared by IntellectualSites.

the class BlockTypeListFlag method getCategory.

private BlockTypeWrapper getCategory(final String blockString) throws FlagParseException {
    if (!blockString.startsWith("#")) {
        throw new FlagParseException(this, blockString, TranslatableCaption.of("flags.flag_error_invalid_block"));
    }
    String categoryId = blockString.substring(1);
    BlockTypeWrapper blockTypeWrapper;
    if (skipCategoryVerification) {
        blockTypeWrapper = BlockTypeWrapper.get(categoryId);
    } else {
        BlockCategory blockCategory = BlockCategory.REGISTRY.get(categoryId);
        if (blockCategory == null) {
            throw new FlagParseException(this, blockString, TranslatableCaption.of("flags.flag_error_invalid_block"));
        }
        blockTypeWrapper = BlockTypeWrapper.get(blockCategory);
    }
    return blockTypeWrapper;
}
Also used : FlagParseException(com.plotsquared.core.plot.flag.FlagParseException) BlockCategory(com.sk89q.worldedit.world.block.BlockCategory)

Example 2 with BlockCategory

use of com.sk89q.worldedit.world.block.BlockCategory in project FastAsyncWorldEdit by IntellectualSites.

the class BlockCategoryPatternParser method parseFromInput.

@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
    if (!input.startsWith("##")) {
        return null;
    }
    String tag = input.substring(2).toLowerCase(Locale.ROOT);
    boolean anyState = false;
    if (tag.startsWith("*")) {
        tag = tag.substring(1);
        anyState = true;
    }
    BlockCategory category = BlockCategory.REGISTRY.get(tag);
    if (category == null) {
        throw new InputParseException(Caption.of("worldedit.error.unknown-tag", TextComponent.of(tag)));
    }
    RandomPattern randomPattern = new RandomPattern();
    Set<BlockType> blocks = category.getAll();
    if (blocks.isEmpty()) {
        throw new InputParseException(Caption.of("worldedit.error.empty-tag", TextComponent.of(category.getId())));
    }
    if (anyState) {
        blocks.stream().flatMap(blockType -> blockType.getAllStates().stream()).forEach(state -> randomPattern.add(state, 1.0));
    } else {
        for (BlockType blockType : blocks) {
            randomPattern.add(blockType.getDefaultState(), 1.0);
        }
    }
    return randomPattern;
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Set(java.util.Set) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) Caption(com.fastasyncworldedit.core.configuration.Caption) BlockCategory(com.sk89q.worldedit.world.block.BlockCategory) ParserContext(com.sk89q.worldedit.extension.input.ParserContext) AliasedParser(com.fastasyncworldedit.core.extension.factory.parser.AliasedParser) List(java.util.List) Stream(java.util.stream.Stream) InputParser(com.sk89q.worldedit.internal.registry.InputParser) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) Locale(java.util.Locale) WorldEdit(com.sk89q.worldedit.WorldEdit) SuggestionHelper(com.sk89q.worldedit.command.util.SuggestionHelper) Pattern(com.sk89q.worldedit.function.pattern.Pattern) Collections(java.util.Collections) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) BlockType(com.sk89q.worldedit.world.block.BlockType) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) BlockCategory(com.sk89q.worldedit.world.block.BlockCategory)

Aggregations

BlockCategory (com.sk89q.worldedit.world.block.BlockCategory)2 Caption (com.fastasyncworldedit.core.configuration.Caption)1 AliasedParser (com.fastasyncworldedit.core.extension.factory.parser.AliasedParser)1 FlagParseException (com.plotsquared.core.plot.flag.FlagParseException)1 WorldEdit (com.sk89q.worldedit.WorldEdit)1 SuggestionHelper (com.sk89q.worldedit.command.util.SuggestionHelper)1 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)1 ParserContext (com.sk89q.worldedit.extension.input.ParserContext)1 Pattern (com.sk89q.worldedit.function.pattern.Pattern)1 RandomPattern (com.sk89q.worldedit.function.pattern.RandomPattern)1 InputParser (com.sk89q.worldedit.internal.registry.InputParser)1 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)1 BlockType (com.sk89q.worldedit.world.block.BlockType)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1