I'm writing a Bukkit plugin to prevent vine growth, after cancelling BlockGrowEvent, the vine is still growing and spreading. How can I prevent vine growth, and does the event even fire when vine grows?
Code:
@EventHandler (ignoreCancelled = true)
public void onVineGrow(BlockGrowEvent event){
event.setCancelled(true);
}
The BlockGrowEvent
is only called when plants such as wheat, sugar cane, a cactus, a watermelon or a pumpkin grow (and some other plants too). To detect vines spreading, listen to the BlockSpreadEvent
. Since this event is cancellable, the block to which the vine is spreading will still be air while you're handling the event, so to check if the block is a vine and not a fire block or mushroom spreading, you can look at the new BlockState
of the block being spread to and check whether its type event.getNewState().getData().getItemType()
is equal to Material.VINE
.