I am making a plugin that needs to know if a block was generated naturally or placed later.
I was trying to use the blockSnapshot.getCreator() method, but it doesnt work anymore when a block was moved by a piston or fell down (gravel, sand, etc). So i tried to set the creator by listening to ChangeBlockEvent.Place.
@Listener(order = Order.LATE)
public void onPiston(final ChangeBlockEvent.Place e, @First final Piston piston) {
this.logger.info("Found Piston Movement!");
e.getTransactions().forEach(trans -> trans.setCustom(BlockSnapshot.builder().from(trans.getFinal()).creator(e.getCause().first(Player.class).map(p -> p.getUniqueId()).orElse(this.uuid)).build()));
e.getTransactions().forEach(trans -> trans.getOriginal().getLocation().ifPresent(loc -> loc.setBlock(BlockSnapshot.builder().from(trans.getFinal()).creator(e.getCause().first(Player.class).map(p -> p.getUniqueId()).orElse(this.uuid)).build().getState(), ServerUtils.getCause(super.getMMO().getContainer()))));
}
Both of these ways did not set the creator properly. Does anybody know how i can make this work?