Search in sources :

Example 1 with DataProcessor

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();
}
Also used : DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) DataProcessor(org.spongepowered.common.data.DataProcessor) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 2 with DataProcessor

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());
}
Also used : DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) DataProcessor(org.spongepowered.common.data.DataProcessor) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 3 with DataProcessor

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();
}
Also used : DataProcessor(org.spongepowered.common.data.DataProcessor) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

DataProcessor (org.spongepowered.common.data.DataProcessor)3 DataTransactionResult (org.spongepowered.api.data.DataTransactionResult)2 IMixinCustomDataHolder (org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1