use of org.lanternpowered.server.data.manipulator.DataManipulatorRegistration in project LanternServer by LanternPowered.
the class IDataHolder method get.
@Override
default <T extends DataManipulator<?, ?>> Optional<T> get(Class<T> containerClass) {
checkNotNull(containerClass, "containerClass");
// Check default registrations
final Optional<DataManipulatorRegistration> optRegistration = DataManipulatorRegistry.get().getBy(containerClass);
if (optRegistration.isPresent()) {
final DataManipulator manipulator = DataHelper.create(this, optRegistration.get());
return manipulator == null ? Optional.empty() : Optional.of((T) (ImmutableDataManipulator.class.isAssignableFrom(containerClass) ? manipulator.asImmutable() : manipulator));
}
// Try the additional containers if they are supported
if (this instanceof AdditionalContainerHolder) {
final AdditionalContainerCollection<DataManipulator<?, ?>> containers = ((AdditionalContainerHolder<DataManipulator<?, ?>>) this).getAdditionalContainers();
return containers.get(containerClass);
}
return Optional.empty();
}
Aggregations