Example #1
0
  /**
   * Scores the specified {@link PotionEffect}.
   *
   * @param effect The effect to score.
   * @return The score.
   * @throws IllegalArgumentException If an effect with an unknown {@link PotionEffectType} was
   *     specified.
   */
  public static double getScore(final PotionEffect effect) throws IllegalArgumentException {
    Preconditions.checkNotNull(effect, "Effect");

    //  Duration, in ticks
    int duration = effect.getDuration();
    //  Level (>= 1 is normal effect, == 0 is no effect, < 0 is inverse effect)
    int level = effect.getAmplifier();
    PotionEffectType effectType = effect.getType();
    PotionClassification classification =
        (level >= 0
            ? PotionUtils.potionEffectTypeImplications.get(effectType)
            : PotionUtils.inversePotionEffectTypeImplications.get(effectType));

    if (effectType == null || classification == null)
      throw new IllegalArgumentException("Unknown (or null) PotionEffectType");

    double score = classification.getScore();
    score *= Math.abs(level);
    return score * ((double) duration / 20);
  }
Example #2
0
 /**
  * Classifies the provided {@link PotionEffect}s as either {@link
  * PotionClassification#BENEFICIAL}, {@link PotionClassification#UNKNOWN}, or {@link
  * PotionClassification#HARMFUL}.
  */
 public static PotionClassification getClassificationForEffects(
     final Iterable<PotionEffect> effects) {
   return PotionClassification.getClassificationForScore(getScore(effects));
 }
Example #3
0
 /**
  * Classifies the provided {@link ThrownPotion} as either {@link PotionClassification#BENEFICIAL},
  * {@link PotionClassification#UNKNOWN}, or {@link PotionClassification#HARMFUL}.
  */
 public static PotionClassification getClassificationForPotion(final ThrownPotion potion) {
   return PotionClassification.getClassificationForScore(getScore(potion));
 }