コード例 #1
0
 @Override
 public DataTransactionResult removeFrom(ValueContainer<?> container) {
   if (container instanceof TileEntityLockable) {
     set((TileEntityLockable) container, "");
     return DataTransactionBuilder.successNoData();
   }
   return DataTransactionBuilder.failNoData();
 }
コード例 #2
0
 @Override
 public DataTransactionResult set(
     DataHolder dataHolder, EyeLocationData manipulator, MergeFunction function) {
   if (!supports(dataHolder)) {
     return DataTransactionBuilder.failResult(manipulator.getValues());
   }
   final ImmutableValue<Double> newValue = manipulator.eyeHeight().asImmutable();
   final EyeLocationData oldManipulator = from(dataHolder).get();
   final ImmutableValue<Double> oldValue = oldManipulator.eyeHeight().asImmutable();
   final EyeLocationData newData = function.merge(oldManipulator, manipulator);
   ((IMixinEntity) dataHolder).setEyeHeight(newData.eyeHeight().get());
   return DataTransactionBuilder.successReplaceResult(newValue, oldValue);
 }
コード例 #3
0
 @Override
 public DataTransactionResult offerToStore(ValueContainer<?> container, Double value) {
   if (supports(container)) {
     final EntityPlayer player = (EntityPlayer) container;
     if (player.getFoodStats() != null) {
       final Double oldValue = (double) player.getFoodStats().getSaturationLevel();
       player.getFoodStats().foodSaturationLevel = value.floatValue();
       return DataTransactionBuilder.successReplaceResult(
           new ImmutableSpongeValue<Double>(Keys.SATURATION, value),
           new ImmutableSpongeValue<Double>(Keys.SATURATION, oldValue));
     }
   }
   return DataTransactionBuilder.failResult(
       new ImmutableSpongeValue<Double>(Keys.SATURATION, value));
 }
 @Override
 public DataTransactionResult removeFrom(ValueContainer<?> container) {
   if (this.supports(container)) {
     final ItemStack skull = (ItemStack) container;
     final Optional<GameProfile> oldData = getVal(skull);
     if (SkullUtils.setProfile(skull, null)) {
       if (oldData.isPresent()) {
         return DataTransactionBuilder.successReplaceResult(
             Collections.emptySet(),
             Collections.singleton(constructImmutableValue(oldData.get())));
       } else {
         return DataTransactionBuilder.successNoData();
       }
     }
   }
   return DataTransactionBuilder.failNoData();
 }
コード例 #5
0
 @SuppressWarnings("unchecked")
 @Override
 public DataTransactionResult offerToStore(ValueContainer<?> container, E value) {
   final ImmutableValue<E> newValue = constructImmutableValue(value);
   if (supports(container)) {
     final DataTransactionBuilder builder = DataTransactionBuilder.builder();
     final Optional<E> oldVal = getVal((C) container);
     try {
       if (set((C) container, value)) {
         if (oldVal.isPresent()) {
           builder.replace(constructImmutableValue(oldVal.get()));
         }
         return builder.result(DataTransactionResult.Type.SUCCESS).success(newValue).build();
       }
       return builder.result(DataTransactionResult.Type.FAILURE).reject(newValue).build();
     } catch (Exception e) {
       Sponge.getLogger().debug("An exception occurred when setting data: ", e);
       return builder.result(DataTransactionResult.Type.ERROR).reject(newValue).build();
     }
   }
   return DataTransactionBuilder.failResult(newValue);
 }
コード例 #6
0
 @Override
 public DataTransactionResult removeFrom(ValueContainer<?> container) {
   return DataTransactionBuilder.failNoData();
 }
コード例 #7
0
 @Override
 public DataTransactionResult remove(DataHolder dataHolder) {
   return DataTransactionBuilder.failNoData();
 }