@Test public void testChangeBlockEvent_filter() { Transaction<BlockSnapshot> transaction = new Transaction<>(mockParam(BlockSnapshot.class), mockParam(BlockSnapshot.class)); when(transaction.getOriginal().getLocation()).thenReturn(Optional.of(new Location<>(mockParam(World.class), Vector3d.ZERO))); ChangeBlockEvent.Break event = SpongeEventFactory.createChangeBlockEventBreak( Cause.of(EventContext.empty(), "none"), Lists.newArrayList(transaction)); event.filter(location -> false); assertThat(transaction.isValid(), is(false)); }
@Override public ActionableResult rollback() throws Exception { DataView entityData = formatEntityData(); Optional<EntitySnapshot> snapshot = Sponge.getRegistry().createBuilder(Builder.class).build(entityData); if (!snapshot.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID); } Optional<Entity> entity = snapshot.get().restore(); if (!entity.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID); } // Don't let it burn to death (again?) entity.get().get(IgniteableData.class).ifPresent(data -> entity.get().offer(data.fireTicks().set(0))); // Heal, it was probably killed. entity.get().get(HealthData.class).ifPresent(data -> entity.get().offer(data.health().set(data.maxHealth().get()))); return ActionableResult.success(new Transaction<>(new SerializableNonExistent(), entity.get())); }
return ActionableResult.success(new Transaction<>(original, resultingBlock));
return ActionableResult.success(new Transaction<>(original, resultingBlock));
/** * Saves event records when a player drops an item. * * @param event Dispense event. */ @Listener(order = Order.POST) public void onDrop(final DropItemEvent.Dispense event, @Root Player spawnCause) { for (Entity entity : event.getEntities()) { if (!(entity instanceof Item)) { continue; } Item item = (Item) entity; Transaction<ItemStackSnapshot> transaction = new Transaction<>(ItemStackSnapshot.NONE, item.item().get()); PrismRecord.create().entity(spawnCause).dropped(transaction).save(); } } }