use of org.spongepowered.common.data.DataProcessor in project SpongeCommon by SpongePowered.
the class MixinDataHolder method remove.
@Override
public DataTransactionResult remove(Class<? extends DataManipulator<?, ?>> containerClass) {
TimingsManager.DATA_GROUP_HANDLER.startTimingIfSync();
SpongeTimings.dataRemoveManipulator.startTimingIfSync();
final Optional<DataProcessor<?, ?>> optional = DataUtil.getWildProcessor(containerClass);
if (optional.isPresent()) {
final DataTransactionResult result = optional.get().remove(this);
SpongeTimings.dataRemoveManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
} else if (this instanceof IMixinCustomDataHolder) {
final DataTransactionResult result = ((IMixinCustomDataHolder) this).removeCustom(containerClass);
SpongeTimings.dataRemoveManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
}
SpongeTimings.dataOfferMultiManipulators.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return DataTransactionResult.failNoData();
}
use of org.spongepowered.common.data.DataProcessor in project SpongeCommon by SpongePowered.
the class MixinDataHolder method offer.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public DataTransactionResult offer(DataManipulator<?, ?> valueContainer, MergeFunction function) {
TimingsManager.DATA_GROUP_HANDLER.startTimingIfSync();
SpongeTimings.dataOfferManipulator.startTimingIfSync();
final Optional<DataProcessor> optional = DataUtil.getWildDataProcessor(valueContainer.getClass());
if (optional.isPresent()) {
final DataTransactionResult result = optional.get().set(this, valueContainer, checkNotNull(function));
SpongeTimings.dataOfferManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
} else if (this instanceof IMixinCustomDataHolder) {
final DataTransactionResult result = ((IMixinCustomDataHolder) this).offerCustom(valueContainer, function);
SpongeTimings.dataOfferManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
}
SpongeTimings.dataOfferManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return DataTransactionResult.failResult(valueContainer.getValues());
}
use of org.spongepowered.common.data.DataProcessor in project SpongeCommon by SpongePowered.
the class SpongeItemStackSnapshot method without.
@SuppressWarnings("rawtypes")
@Override
public Optional<ItemStackSnapshot> without(Class<? extends ImmutableDataManipulator<?, ?>> containerClass) {
final ItemStack copiedStack = this.privateStack.copy();
Optional<DataProcessor> processorOptional = DataUtil.getWildImmutableProcessor(containerClass);
if (processorOptional.isPresent()) {
processorOptional.get().remove(copiedStack);
return Optional.of(copiedStack.createSnapshot());
}
// todo custom data
return Optional.empty();
}
Aggregations