What event do pistons use to update blocks?

Discussion in 'Spigot Plugin Development' started by caughtbiggay, Nov 10, 2018.

  1. I have this:
    Code (Java):
        @EventHandler
        public void onPiston(BlockPistonExtendEvent event) {
            List<Block> bl = event.getBlocks();
            for (Block b : bl) {
                if (Protection.NoBreak(b.getLocation())) event.setCancelled(true);
                if (Protection.NoNothing(b.getLocation())) event.setCancelled(true);
            }
        }
    But it still lets pistons push blocks 1 block into the protected area because the event.getBlocks() list is the blocks before they are pushed
     
  2. I do not know if there is a simpler way but I would try to get the blocks after pushing by using the piston's facing.
     
  3. hmm, interesting that the event only lets 1 block enter the protected zone.
    That is the clue perhaps?
    Use the events getDirection() and adjust the blocks location check by the direction it is facing.
     
    #3 Goldentoenail, Nov 10, 2018
    Last edited: Nov 10, 2018

Share This Page