How to know if a plant has fully grown?

Viewed 399

I have a BlockBreakEvent and need to know if the breaked block is a fully grown wheat seed.

My code so far is:

@EventHandler
public void onBreak(BlockBreakEvent e) {
    Player player = e.getPlayer();
    String name = player.getName();
    if (e.getBlock().getType() == Material.WHEAT) {
        // ...
    }

}

Right now my if is also entered when the block is not fully grown yet. So how can I edit this condition to also check for the seed being fully grown?

I am using CraftBukkit 1.15.2.

1 Answers

You can read the "age" like this:

final Ageable ageable = (Ageable) event.getClickedBlock().getState().getBlockData();
if (ageable.getAge() == 7) 
{
    // wheat is full grown.
};

I got the information from this page but wanted to preserve it here in case the link dies.

Related