#Cancelling piston head movement

1 messages · Page 1 of 1 (latest)

crimson quarry
#

Hi guys. Is there an event responsible for piston head movement? BlockPistonExtendEvent and BlockPistonRetractEvent seem to only refer to blocks pushed by the piston.

dusky mural
#

if theres a block powered event cancel that

crimson quarry
#

I'm currently writing a plugin which allows users to create plots to protect their possessions. I wrote PistonProtection class which ensures pistons only work inside and outside the plots and can't be used to move anything in or out other player's plot. The code works fine but I couldn't find anything whichi would help me cancel piston head movement

crimson quarry
#

i tried to find something but i couldn't

#

i also tried using BlockPistonEvent but im getting an error

#
`   @EventHandler
    public void onBlockPistonEvent(final BlockPistonEvent event){
        PlotManager plotManager = ChunkyPlots.plugin.plotManager;

        Block piston = event.getBlock();
        Block extendedToBlock = piston.getRelative(event.getDirection());

        Plot sourcePlot = plotManager.getPlotByBlock(piston);
        Plot destinationPlot = plotManager.getPlotByBlock(extendedToBlock);

        if(sourcePlot == null && destinationPlot != null){
            event.setCancelled(true);
        } else if (sourcePlot != null && destinationPlot != null){
            if(!sourcePlot.hasTheSameOwnerAs(destinationPlot)){
                event.setCancelled(true);
            }
        }
    }```
#

it looks like it has nothing to do with my code

#

maybe BlockPistonEvent is abstract?

#

either way i cant seem to be able to do it

proper drift
#

Yeah, abstract event, can't listen to it

#

I'm not sure what you mean by

I couldn't find anything whichi would help me cancel piston head movement
because cancelling the extract and retract events should do exactly that

crimson quarry
#

hmm... maybe i didn't include a case for it, i'll review it now

crimson quarry
#

i just didn't check piston along with other blocks

#

tysm ❤️