use of org.spongepowered.api.effect.particle.ParticleOption in project SpongeCommon by SpongePowered.
the class SpongeParticleEffectBuilder method buildContent.
@Override
protected Optional<ParticleEffect> buildContent(DataView container) throws InvalidDataException {
if (!container.contains(DataQueries.PARTICLE_TYPE, DataQueries.PARTICLE_OPTIONS)) {
return Optional.empty();
}
ParticleType particleType = container.getCatalogType(DataQueries.PARTICLE_TYPE, ParticleType.class).get();
Map<ParticleOption<?>, Object> options = new HashMap<>();
container.getViewList(DataQueries.PARTICLE_OPTIONS).get().forEach(view -> {
ParticleOption<?> option = view.getCatalogType(DataQueries.PARTICLE_OPTION_KEY, ParticleOption.class).get();
Object value;
if (option.getValueType().isAssignableFrom(DataSerializable.class)) {
value = view.getSerializable(DataQueries.PARTICLE_OPTION_VALUE, (Class<? extends DataSerializable>) option.getValueType()).get();
} else {
value = view.getObject(DataQueries.PARTICLE_OPTION_VALUE, option.getValueType()).get();
}
options.put(option, value);
});
return Optional.of(new SpongeParticleEffect((SpongeParticleType) particleType, options));
}
use of org.spongepowered.api.effect.particle.ParticleOption in project LanternServer by LanternPowered.
the class LanternParticleEffectBuilder method buildContent.
@Override
protected Optional<ParticleEffect> buildContent(DataView container) throws InvalidDataException {
if (!container.contains(DataQueries.PARTICLE_TYPE, DataQueries.PARTICLE_OPTIONS)) {
return Optional.empty();
}
ParticleType particleType = container.getCatalogType(DataQueries.PARTICLE_TYPE, ParticleType.class).get();
Map<ParticleOption<?>, Object> options = new HashMap<>();
container.getViewList(DataQueries.PARTICLE_OPTIONS).get().forEach(view -> {
ParticleOption option = view.getCatalogType(DataQueries.PARTICLE_OPTION_KEY, ParticleOption.class).get();
Object value;
if (option.getValueType().isAssignableFrom(DataSerializable.class)) {
value = view.getSerializable(DataQueries.PARTICLE_OPTION_VALUE, option.getValueType()).get();
} else {
value = view.getObject(DataQueries.PARTICLE_OPTION_VALUE, option.getValueType()).get();
}
options.put(option, value);
});
return Optional.of(new LanternParticleEffect((LanternParticleType) particleType, options));
}
Aggregations