Search in sources :

Example 1 with InteractContainerEvent

use of org.spongepowered.api.event.item.inventory.container.InteractContainerEvent in project SpongeCommon by SpongePowered.

the class SpongeEventManager method preparePost.

protected final NoExceptionClosable preparePost(final Event event) {
    if (event instanceof InteractContainerEvent) {
        // Track usage of Containers
        final ContainerBridge bridge = ((ContainerBridge) ((InteractContainerEvent) event).container());
        bridge.bridge$setInUse(true);
        return new ContainerInUseClosable(bridge);
    }
    return SpongeEventManager.NULL_CLOSABLE;
}
Also used : InteractContainerEvent(org.spongepowered.api.event.item.inventory.container.InteractContainerEvent) ContainerBridge(org.spongepowered.common.bridge.world.inventory.container.ContainerBridge)

Example 2 with InteractContainerEvent

use of org.spongepowered.api.event.item.inventory.container.InteractContainerEvent in project SpongeCommon by SpongePowered.

the class CloseMenuTransaction method generateEvent.

@Override
public Optional<InteractContainerEvent> generateEvent(final PhaseContext<@NonNull ?> context, @Nullable final GameTransaction<@NonNull ?> parent, final ImmutableList<GameTransaction<InteractContainerEvent>> gameTransactions, final Cause currentCause) {
    final ItemStackSnapshot resultingCursor = ItemStackUtil.snapshotOf(this.player.inventory.getCarried());
    final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(this.cursor, resultingCursor);
    final InteractContainerEvent.Close event = SpongeEventFactory.createInteractContainerEventClose(currentCause, (Container) this.menu, cursorTransaction, (Container) this.menu, this.slotTransactions == null ? Collections.emptyList() : this.slotTransactions);
    return Optional.of(event);
}
Also used : SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Transaction(org.spongepowered.api.data.Transaction) GameTransaction(org.spongepowered.common.event.tracking.context.transaction.GameTransaction) InteractContainerEvent(org.spongepowered.api.event.item.inventory.container.InteractContainerEvent) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot)

Example 3 with InteractContainerEvent

use of org.spongepowered.api.event.item.inventory.container.InteractContainerEvent in project SpongeCommon by SpongePowered.

the class OpenMenuTransaction method generateEvent.

@Override
public Optional<InteractContainerEvent> generateEvent(final PhaseContext<@NonNull ?> context, @Nullable final GameTransaction<@NonNull ?> parent, final ImmutableList<GameTransaction<InteractContainerEvent>> gameTransactions, final Cause currentCause) {
    final ItemStackSnapshot resultingCursor = ItemStackUtil.snapshotOf(this.player.inventory.getCarried());
    final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(this.cursor, resultingCursor);
    final InteractContainerEvent.Open event = SpongeEventFactory.createInteractContainerEventOpen(currentCause, (Container) this.menu, cursorTransaction);
    return Optional.of(event);
}
Also used : GameTransaction(org.spongepowered.common.event.tracking.context.transaction.GameTransaction) Transaction(org.spongepowered.api.data.Transaction) InteractContainerEvent(org.spongepowered.api.event.item.inventory.container.InteractContainerEvent) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot)

Aggregations

InteractContainerEvent (org.spongepowered.api.event.item.inventory.container.InteractContainerEvent)3 Transaction (org.spongepowered.api.data.Transaction)2 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)2 GameTransaction (org.spongepowered.common.event.tracking.context.transaction.GameTransaction)2 SlotTransaction (org.spongepowered.api.item.inventory.transaction.SlotTransaction)1 ContainerBridge (org.spongepowered.common.bridge.world.inventory.container.ContainerBridge)1