Need help to deny water flow

@Listener
    public void stopLiquidFlow(ChangeBlockEvent.Place event) {
		System.out.println("WATER FLOW");
		BlockSnapshot snapshot = event.getTransactions().get(0).getFinal();
        Optional<MatterProperty> matter = snapshot.getState().getProperty(MatterProperty.class);
        if (matter.isPresent() && matter.get().getValue() == Matter.LIQUID) {
            event.setCancelled(true);
        }
    }

code ↑↑↑↑↑↑↑↑
the water can not flowing,
but player cant place a water block(use bucket)
and i see the event.getTransactions().get(0).getFianl() block type was FLOWING_WATER, not was WATER

You seem to have a syntax error in line 4, which probably prevents you from actually getting the BlockSnapshot:

BlockSnapshot snapshot = event.getTransactions().get(0).getFianl();

That should probably be getFinal(); :slight_smile:

It only was I am in copy problem
That’s not what reason

In that case, I am afraid we will have to help for somebody else to help you, as I am not a java developer

Well, what you have described seems to be exactly the expected behavior of this code (if some number of blocks change, and the first one will end up being a liquid, cancel the event). Try adding @Root LocatableBlock block to the method parameters, so it will only call if another block is the cause. You also want to iterate over the transactions, since multiple blocks may be changed by this but you’re only checking the first one.

look like this?
↓↓↓↓↓↓
@Listener
public void stopLiquidFlow(ChangeBlockEvent.Place event,@Root LocatableBlock block) {
System.out.println(“WATER FLOW”);
BlockSnapshot snapshot = event.getTransactions().get(0).getFinal();
Optional matter = snapshot.getState().getProperty(MatterProperty.class);
if (matter.isPresent() && matter.get().getValue() == Matter.LIQUID) {
event.setCancelled(true);
}
}

Well, that’s half of what I said.

@Listener
public void stopLiquidFlow(ChangeBlockEvent.Place event,@Root LocatableBlock block) {
    System.out.println(“WATER FLOW”);
    for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
        Optional<MatterProperty> matter = trans.getFinal().getState().getProperty(MatterProperty.class);
        if (matter.isPresent() && matter.get().getValue() == Matter.LIQUID) {
            event.setCancelled(true);
        }
    }
}

Tip: Put three backticks followed by your language name (```java) on a line by themselves before code, and three backticks (```) on a line by themselves after your code, in order to syntax highlight, preserve indentation, and not misinterpret generics as HTML tags.

ok thx!!!!!!!XD

As WaterFlow can be super spammy we don’t fire .Place events for flowing water changes (except when they break stuff etc.)
Use ChangeBlockEvent.Pre if you want to cancel all water-flow.

hey dude
i go try this but that useless
that code cant catch water flow event and other place event

My bad for missing that, but the post’s sort of right there.