Search in sources :

Example 1 with ValueProcessor

use of org.spongepowered.common.data.ValueProcessor in project SpongeCommon by SpongePowered.

the class MixinDataHolder method remove.

@Override
public DataTransactionResult remove(Key<?> key) {
    TimingsManager.DATA_GROUP_HANDLER.startTimingIfSync();
    SpongeTimings.dataRemoveKey.startTimingIfSync();
    final Optional<ValueProcessor<?, ?>> optional = DataUtil.getWildValueProcessor(checkNotNull(key));
    if (optional.isPresent()) {
        final DataTransactionResult result = optional.get().removeFrom(this);
        SpongeTimings.dataRemoveKey.stopTimingIfSync();
        TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
        return result;
    } else if (this instanceof IMixinCustomDataHolder) {
        final DataTransactionResult result = ((IMixinCustomDataHolder) this).removeCustom(key);
        SpongeTimings.dataRemoveKey.stopTimingIfSync();
        TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
        return result;
    }
    SpongeTimings.dataRemoveKey.stopTimingIfSync();
    TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
    return DataTransactionResult.failNoData();
}
Also used : ValueProcessor(org.spongepowered.common.data.ValueProcessor) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 2 with ValueProcessor

use of org.spongepowered.common.data.ValueProcessor in project SpongeCommon by SpongePowered.

the class MixinDataHolder method offer.

@Override
public <E> DataTransactionResult offer(Key<? extends BaseValue<E>> key, E value) {
    TimingsManager.DATA_GROUP_HANDLER.startTimingIfSync();
    SpongeTimings.dataOfferKey.startTimingIfSync();
    final Optional<ValueProcessor<E, ? extends BaseValue<E>>> optional = DataUtil.getBaseValueProcessor(key);
    if (optional.isPresent()) {
        final DataTransactionResult result = optional.get().offerToStore(this, value);
        SpongeTimings.dataOfferKey.stopTimingIfSync();
        TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
        return result;
    } else if (this instanceof IMixinCustomDataHolder) {
        final DataTransactionResult result = ((IMixinCustomDataHolder) this).offerCustom(key, value);
        SpongeTimings.dataOfferKey.stopTimingIfSync();
        TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
        return result;
    }
    SpongeTimings.dataOfferKey.stopTimingIfSync();
    TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
    return DataTransactionResult.failNoData();
}
Also used : BaseValue(org.spongepowered.api.data.value.BaseValue) ValueProcessor(org.spongepowered.common.data.ValueProcessor) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Aggregations

DataTransactionResult (org.spongepowered.api.data.DataTransactionResult)2 ValueProcessor (org.spongepowered.common.data.ValueProcessor)2 IMixinCustomDataHolder (org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)2 BaseValue (org.spongepowered.api.data.value.BaseValue)1