I have added this else if statement to let you jump out of the water
if(flag && e.motionY < 0.0D){
if(!Minecraft.getMinecraft().gameSettings.keyBindJump.getIsKeyPressed()){
e.motionY = 0.0D;
}else if(Minecraft.getMinecraft().gameSettings.keyBindJump.getIsKeyPressed()){
e.motionY = 0.5D;
}