use of org.lanternpowered.server.data.manipulator.DataManipulatorRegistration in project LanternServer by LanternPowered.
the class IDataHolder method supports.
@Override
default boolean supports(Class<? extends DataManipulator<?, ?>> containerClass) {
checkNotNull(containerClass, "containerClass");
// Offer all the default key values as long if they are supported
final Optional<DataManipulatorRegistration> optRegistration = DataManipulatorRegistry.get().getBy(containerClass);
if (optRegistration.isPresent()) {
final DataManipulatorRegistration registration = optRegistration.get();
for (Key key : (Set<Key>) registration.getRequiredKeys()) {
if (!supports(key)) {
return false;
}
}
return true;
}
// Support all the additional manipulators
return this instanceof AdditionalContainerHolder;
}
use of org.lanternpowered.server.data.manipulator.DataManipulatorRegistration in project LanternServer by LanternPowered.
the class IDataHolder method getContainers.
@Override
default Collection<DataManipulator<?, ?>> getContainers() {
final ImmutableList.Builder<DataManipulator<?, ?>> builder = ImmutableList.builder();
for (DataManipulatorRegistration registration : DataManipulatorRegistry.get().getAll()) {
final DataManipulator manipulator = DataHelper.create(this, registration);
if (manipulator != null) {
builder.add(manipulator);
}
}
// Try the additional manipulators if they are supported
if (this instanceof AdditionalContainerHolder) {
final AdditionalContainerCollection<DataManipulator<?, ?>> containers = ((AdditionalContainerHolder<DataManipulator<?, ?>>) this).getAdditionalContainers();
containers.getAll().forEach(manipulator -> builder.add(manipulator.copy()));
}
return builder.build();
}
use of org.lanternpowered.server.data.manipulator.DataManipulatorRegistration in project LanternServer by LanternPowered.
the class IImmutableDataHolderBase method getContainers.
@Override
default List<ImmutableDataManipulator<?, ?>> getContainers() {
final ImmutableList.Builder<ImmutableDataManipulator<?, ?>> builder = ImmutableList.builder();
for (DataManipulatorRegistration registration : DataManipulatorRegistry.get().getAll()) {
final ImmutableDataManipulator manipulator = (ImmutableDataManipulator) ImmutableContainerCache.get(this, registration, registration.getImmutableManipulatorClass()).orElse(null);
if (manipulator != null) {
builder.add(manipulator);
}
}
if (this instanceof AdditionalContainerHolder) {
final AdditionalContainerCollection<ImmutableDataManipulator<?, ?>> manipulators = ((AdditionalContainerHolder<ImmutableDataManipulator<?, ?>>) this).getAdditionalContainers();
manipulators.getAll().forEach(builder::add);
}
return builder.build();
}
use of org.lanternpowered.server.data.manipulator.DataManipulatorRegistration in project LanternServer by LanternPowered.
the class ICompositeValueStore method offerFastNoEvents.
default boolean offerFastNoEvents(H valueContainer, MergeFunction function) {
if (valueContainer instanceof IDataManipulatorBase) {
// Offer all the default key values as long if they are supported
final Optional<DataManipulatorRegistration> optRegistration = DataManipulatorRegistry.get().getByMutable(((IDataManipulatorBase) valueContainer).getMutableType());
if (optRegistration.isPresent()) {
if (function == MergeFunction.FORCE_NOTHING) {
return true;
} else if (function != MergeFunction.IGNORE_ALL) {
ValueContainer old = DataHelper.create(this, optRegistration.get());
if (valueContainer instanceof IImmutableDataManipulator && old != null) {
old = ((DataManipulator) old).asImmutable();
}
valueContainer = (H) function.merge(old, valueContainer);
}
boolean success = false;
for (ImmutableValue value : valueContainer.getValues()) {
if (offerFast(value)) {
success = true;
break;
}
}
return success;
}
}
if (this instanceof AdditionalContainerHolder) {
final AdditionalContainerCollection<H> containers = ((AdditionalContainerHolder<H>) this).getAdditionalContainers();
final Class key = valueContainer.getClass();
final H old = (H) containers.get(key).orElse(null);
final H merged = function.merge(old, valueContainer);
containers.offer(merged);
return true;
}
return false;
}
use of org.lanternpowered.server.data.manipulator.DataManipulatorRegistration in project LanternServer by LanternPowered.
the class ICompositeValueStore method offerNoEvents.
default DataTransactionResult offerNoEvents(H valueContainer, MergeFunction function) {
if (valueContainer instanceof IDataManipulatorBase) {
// Offer all the default key values as long if they are supported
final Optional<DataManipulatorRegistration> optRegistration = DataManipulatorRegistry.get().getByMutable(((IDataManipulatorBase) valueContainer).getMutableType());
if (optRegistration.isPresent()) {
if (function != MergeFunction.IGNORE_ALL) {
ValueContainer old = DataHelper.create(this, optRegistration.get());
if (valueContainer instanceof IImmutableDataManipulator && old != null) {
old = ((DataManipulator) old).asImmutable();
}
valueContainer = (H) function.merge(old, valueContainer);
}
final DataTransactionResult.Builder builder = DataTransactionResult.builder();
boolean success = false;
for (ImmutableValue value : valueContainer.getValues()) {
final DataTransactionResult result = offerNoEvents(value);
if (result.isSuccessful()) {
builder.success(value);
builder.replace(result.getReplacedData());
success = true;
} else {
builder.reject(value);
}
}
if (success) {
builder.result(DataTransactionResult.Type.SUCCESS);
} else {
builder.result(DataTransactionResult.Type.FAILURE);
}
return builder.build();
}
}
if (this instanceof AdditionalContainerHolder) {
final AdditionalContainerCollection<H> containers = ((AdditionalContainerHolder<H>) this).getAdditionalContainers();
final Class key = valueContainer.getClass();
final H old = (H) containers.get(key).orElse(null);
final H merged = function.merge(old, valueContainer);
containers.offer(merged);
final DataTransactionResult.Builder builder = DataTransactionResult.builder().result(DataTransactionResult.Type.SUCCESS);
builder.success(merged.getValues());
if (old != null) {
builder.replace(old.getValues());
}
return builder.build();
}
return DataTransactionResult.failNoData();
}
Aggregations