In an "onPlayerHurt" event, here's a simple example
@ForgeSubscribe
public void onPlayerHurt(LivingHurtEvent event) {
if (event.entityLiving instanceof EntityPlayer) {
EntityPlayerMP player = (EntityPlayerMP)event.entityLiving;
player.capabilities.allowEdit = false;
player.capabilities.allowFlying = true;
player.capabilities.disableDamage = true;
}
}
Again, only disableDamage works.