All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.craftbukkit.potion.CraftPotionBrewer Maven / Gradle / Ivy

package org.bukkit.craftbukkit.potion;

import com.google.common.collect.Maps;
import net.minecraft.server.MobEffect;
import org.bukkit.potion.PotionBrewer;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class CraftPotionBrewer implements PotionBrewer {
  private static final Map> cache = Maps.newHashMap();

  public Collection getEffectsFromDamage(int damage) {
    if (cache.containsKey(damage))
      return cache.get(damage);

    List mcEffects = net.minecraft.server.PotionBrewer.getEffects(damage, false);
    List effects = new ArrayList();
    if (mcEffects == null)
      return effects;

    for (Object raw : mcEffects) {
      if (raw == null || !(raw instanceof MobEffect))
        continue;
      MobEffect mcEffect = (MobEffect) raw;
      PotionEffect effect = new PotionEffect(PotionEffectType.getById(mcEffect.getEffectId()),
        mcEffect.getDuration(), mcEffect.getAmplifier());
      // Minecraft PotionBrewer applies duration modifiers automatically.
      effects.add(effect);
    }

    cache.put(damage, effects);

    return effects;
  }

  public PotionEffect createEffect(PotionEffectType potion, int duration, int amplifier) {
    return new PotionEffect(potion, potion.isInstant() ? 1 : (int) (duration * potion.getDurationModifier()),
      amplifier);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy