Try this. check if potion is active, if no then add else combine.
if (!player.isPotionActive(potion.id))
player.addPotionEffect(new PotionEffect(potion.id, duration, amplifier, isAmbient));
else {
PotionEffect potionEffect = player.getActivePotionEffect(potion);
if (potionEffect.getDuration() < duration)
potionEffect.combine(new PotionEffect(potion.id, duration, amplifier, isAmbient));
}
}