Search in sources :

Example 51 with Transaction

use of org.spongepowered.api.data.Transaction in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method onSignBreak.

@Listener(order = Order.LATE)
public void onSignBreak(ChangeBlockEvent.Break e) {
    if (e.isCancelled())
        return;
    for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
        BlockSnapshot snapshot = transaction.getOriginal();
        Location<World> loc = snapshot.getLocation().orElse(null);
        BlockState state = snapshot.getState();
        BlockState above = loc.getExtent().getBlock(0, 1, 0);
        if (above.getType() != BlockTypes.STANDING_SIGN && above.getType() != BlockTypes.WALL_SIGN)
            return;
        ChangeBlockEvent.Break bbe = new ChangeBlockEvent.Break() {

            private boolean cancelled = false;

            @SuppressWarnings("serial")
            @Override
            public List<Transaction<BlockSnapshot>> getTransactions() {
                return new ArrayList<Transaction<BlockSnapshot>>() {

                    {
                        add(transaction);
                    }
                };
            }

            @Override
            public Cause getCause() {
                return e.getCause();
            }

            @Override
            public boolean isCancelled() {
                return cancelled;
            }

            @Override
            public void setCancelled(boolean cancel) {
                this.cancelled = cancel;
            }
        };
        onBreak(bbe);
        e.setCancelled(bbe.isCancelled());
    }
}
Also used : ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) BlockState(org.spongepowered.api.block.BlockState) Transaction(org.spongepowered.api.data.Transaction) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Aggregations

Transaction (org.spongepowered.api.data.Transaction)51 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)32 SlotTransaction (org.spongepowered.api.item.inventory.transaction.SlotTransaction)28 World (org.spongepowered.api.world.World)19 ArrayList (java.util.ArrayList)15 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)15 CauseStackManager (org.spongepowered.api.event.CauseStackManager)11 Entity (org.spongepowered.api.entity.Entity)10 ChangeBlockEvent (org.spongepowered.api.event.block.ChangeBlockEvent)10 ClickInventoryEvent (org.spongepowered.api.event.item.inventory.ClickInventoryEvent)10 List (java.util.List)8 BlockPos (net.minecraft.util.math.BlockPos)8 SpongeEventFactory (org.spongepowered.api.event.SpongeEventFactory)8 ItemStack (org.spongepowered.api.item.inventory.ItemStack)8 CauseStack (org.lanternpowered.server.event.CauseStack)7 Sponge (org.spongepowered.api.Sponge)7 Player (org.spongepowered.api.entity.living.player.Player)7 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)7 ImmutableList (com.google.common.collect.ImmutableList)6 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)6