package org.bukkit.craftbukkit.potion; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.item.alchemy.PotionRegistry; import org.bukkit.potion.PotionBrewer; import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; public class CraftPotionBrewer implements PotionBrewer { private static final Map> cache = Maps.newHashMap(); @Override public Collection getEffects(PotionType damage, boolean upgraded, boolean extended) { if (cache.containsKey(damage)) return cache.get(damage); List mcEffects = PotionRegistry.a(CraftPotionUtil.fromBukkit(new PotionData(damage, extended, upgraded))).a(); ImmutableList.Builder builder = new ImmutableList.Builder(); for (MobEffect effect : mcEffects) { builder.add(CraftPotionUtil.toBukkit(effect)); } cache.put(damage, builder.build()); return cache.get(damage); } @Override public Collection getEffectsFromDamage(int damage) { return new ArrayList(); } @Override public PotionEffect createEffect(PotionEffectType potion, int duration, int amplifier) { return new PotionEffect(potion, potion.isInstant() ? 1 : (int) (duration * potion.getDurationModifier()), amplifier); } }