For stun detection there is probably a config variable. But if you don't want to go into that, you can simply check the height of your players model (the stun particles become part of the player model, I assume).
Something like myPlayer().getModelHeight() > defaultHeight.
You'll have to check what the default model height is for your player while it's not stunned. This may differ depending on hair/helm, though.
Alternatively, check the verticecount on the model.