use of org.lanternpowered.server.data.manipulator.IDataManipulatorBase 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.IDataManipulatorBase 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