More straightforward to:

if (weapon.containsEnchantment(Enchantment.ARROW_DAMAGE)) {
  return weapon.getEnchantmentLevel(Enchantment.ARROW_DAMAGE);
}
return 0;