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
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.
@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.
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.