I'll try to break this down for you:
First off, this shouldn't be handled on the client, so:
if(dog.world.isRemote)
return;
Secondly there are the conditions for the dog to have this ability, you can add them to the same if statement:
Since we reverse the conditions, we use "OR" instead of "AND", and we reverse each statement.
if(dog.world.isRemote || masterOrder != 4 || dog.getHealth() <= Constants.lowHealthLevel || dog.isChild() || level < 1)
return;
Now, it's time to check the cooldown.
First we check if the cooldown is more than 0, meaning it's still on cooldown. If it is we will return. We then reduce it by one, so that it will eventually be 0.
if(cooldown > 0){
cooldown--;
return;
}
cooldown = level == 5 ? 5 : 20; //5 will happen 4 times in a second and 20 will happen once in a second - are these really the values, you want?
Then there's the damage, remember there was no reason to do this stuff, before you had even checked the cooldown:
byte damage = (byte) (level == 5 ? 10 : level);
//Or if 5 isn't the max level, maybe this is what you want:
byte damage = (byte) (level > 4 ? level+5 : level);
I don't know, if you know that operator (a ? b : c), but basically, it's like this:
byte damage;
if(level == 5)
byte = (byte) 10;
else
byte = level;
Now, it's time to do the action:
for(EntityMob mob : list) {//There's no reason to check if the list is empty, the for loop won't be entered, if there are no elements in it
//I believe all of these will run on the client as well, if called on the server
dog.playSound(SoundEvents.ENTITY_WOLF_GROWL, 1f, 1f);
mob.spawnExplosionParticle();
mob.attackEntityFrom(DamageSource.GENERIC, damage);
}
Then, that should work. I won't be posting the full code, as I want you to read all of it, and put it together yourself. It also might have some typos.
One thing I am concerned about, though is the cooldown simply being a variable. I would probably store it in NBT or dataManager.
You should also initialize the value.