Search in sources :

Example 6 with DataManipulatorRegistration

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();
}
Also used : ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) DataManipulatorRegistration(org.lanternpowered.server.data.manipulator.DataManipulatorRegistration) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator)

Aggregations

DataManipulatorRegistration (org.lanternpowered.server.data.manipulator.DataManipulatorRegistration)6 ImmutableDataManipulator (org.spongepowered.api.data.manipulator.ImmutableDataManipulator)4 DataManipulator (org.spongepowered.api.data.manipulator.DataManipulator)3 ImmutableList (com.google.common.collect.ImmutableList)2 IDataManipulatorBase (org.lanternpowered.server.data.manipulator.IDataManipulatorBase)2 IImmutableDataManipulator (org.lanternpowered.server.data.manipulator.immutable.IImmutableDataManipulator)2 ValueContainer (org.spongepowered.api.data.value.ValueContainer)2 ImmutableValue (org.spongepowered.api.data.value.immutable.ImmutableValue)2 Set (java.util.Set)1 DataTransactionResult (org.spongepowered.api.data.DataTransactionResult)1 Key (org.spongepowered.api.data.key.Key)1