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;
}
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;
}
Aggregations