use of org.spongepowered.api.data.type.BannerPatternShape in project SpongeCommon by SpongePowered.
the class SpongePatternLayerBuilder method buildContent.
@Override
protected Optional<PatternLayer> buildContent(DataView container) throws InvalidDataException {
checkNotNull(container);
if (!container.contains(DataQueries.BANNER_SHAPE_ID) || !container.contains(DataQueries.BANNER_COLOR)) {
return Optional.empty();
}
String id = container.getString(DataQueries.BANNER_SHAPE_ID).get();
// We can get these pattern shapes from the game registry willy nilly, however, we still need to validate
// that the pattern exists, if it doesn't, well, thow an InvalidDataException!
Optional<BannerPatternShape> shapeOptional = Sponge.getRegistry().getType(BannerPatternShape.class, id);
if (!shapeOptional.isPresent()) {
throw new InvalidDataException("The provided container has an invalid banner pattern shape entry!");
}
// Now we need to validate the dye color of course...
String dyeColorId = container.getString(DataQueries.BANNER_COLOR).get();
Optional<DyeColor> colorOptional = Sponge.getRegistry().getType(DyeColor.class, dyeColorId);
if (!colorOptional.isPresent()) {
throw new InvalidDataException("The provided container has an invalid dye color entry!");
}
return Optional.of(new SpongePatternLayer(shapeOptional.get(), colorOptional.get()));
}
Aggregations