use of org.spongepowered.api.data.DataTransactionResult in project SpongeCommon by SpongePowered.
the class MinecartBlockDataProcessor method remove.
@Override
public DataTransactionResult remove(DataHolder dataHolder) {
if (dataHolder instanceof EntityMinecart) {
EntityMinecart cart = (EntityMinecart) dataHolder;
DataTransactionResult.Builder builder = DataTransactionResult.builder().result(DataTransactionResult.Type.SUCCESS);
if (cart.hasDisplayTile()) {
ImmutableValue<BlockState> block = new ImmutableSpongeValue<>(Keys.REPRESENTED_BLOCK, (BlockState) cart.getDisplayTile());
ImmutableValue<Integer> offset = new ImmutableSpongeValue<>(Keys.OFFSET, cart.getDisplayTileOffset());
cart.setHasDisplayTile(false);
builder.replace(block).replace(offset);
}
return builder.build();
}
return DataTransactionResult.failNoData();
}
use of org.spongepowered.api.data.DataTransactionResult in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method offer.
@Override
public DataTransactionResult offer(int x, int y, int z, DataManipulator<?, ?> manipulator, MergeFunction function) {
final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
final ImmutableDataManipulator<?, ?> immutableDataManipulator = manipulator.asImmutable();
if (blockState.supports((Class) immutableDataManipulator.getClass())) {
final List<ImmutableValue<?>> old = new ArrayList<>(blockState.getValues());
final BlockState newState = blockState.with(immutableDataManipulator).get();
old.removeAll(newState.getValues());
setBlock(x, y, z, newState);
return DataTransactionResult.successReplaceResult(old, manipulator.getValues());
}
return getTileEntity(x, y, z).map(tileEntity -> tileEntity.offer(manipulator, function)).orElseGet(() -> DataTransactionResult.failResult(manipulator.getValues()));
}
use of org.spongepowered.api.data.DataTransactionResult 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();
}
use of org.spongepowered.api.data.DataTransactionResult 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.api.data.DataTransactionResult in project SpongeCommon by SpongePowered.
the class MixinDataHolder method offer.
@Override
public DataTransactionResult offer(Iterable<DataManipulator<?, ?>> valueContainers) {
TimingsManager.DATA_GROUP_HANDLER.startTimingIfSync();
SpongeTimings.dataOfferMultiManipulators.startTimingIfSync();
DataTransactionResult.Builder builder = DataTransactionResult.builder();
for (DataManipulator<?, ?> manipulator : valueContainers) {
final DataTransactionResult result = offer(manipulator);
if (!result.getRejectedData().isEmpty()) {
builder.reject(result.getRejectedData());
}
if (!result.getReplacedData().isEmpty()) {
builder.replace(result.getReplacedData());
}
if (!result.getSuccessfulData().isEmpty()) {
builder.success(result.getSuccessfulData());
}
final DataTransactionResult.Type type = result.getType();
builder.result(type);
switch(type) {
case UNDEFINED:
case ERROR:
case CANCELLED:
SpongeTimings.dataOfferMultiManipulators.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return builder.build();
default:
break;
}
}
SpongeTimings.dataOfferMultiManipulators.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return builder.build();
}
Aggregations