[Bleeding] Added Potions API. Fixes BUKKIT-389
By: fullwall <fullwall@optusnet.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package org.bukkit.craftbukkit.potion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.server.MobEffect;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionBrewer;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
public class CraftPotionBrewer implements PotionBrewer {
|
||||
private static final Map<Integer, Collection<PotionEffect>> cache = Maps.newHashMap();
|
||||
|
||||
public Collection<PotionEffect> getEffectsFromDamage(int damage) {
|
||||
if (cache.containsKey(damage))
|
||||
return cache.get(damage);
|
||||
|
||||
List<?> mcEffects = net.minecraft.server.PotionBrewer.a(damage, false);
|
||||
List<PotionEffect> effects = new ArrayList<PotionEffect>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.bukkit.craftbukkit.potion;
|
||||
|
||||
import net.minecraft.server.MobEffectList;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class CraftPotionEffectType extends PotionEffectType {
|
||||
private final MobEffectList handle;
|
||||
|
||||
public CraftPotionEffectType(MobEffectList handle) {
|
||||
super(handle.id);
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurationModifier() {
|
||||
return handle.d();
|
||||
}
|
||||
|
||||
public MobEffectList getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
switch (handle.id) {
|
||||
case 1:
|
||||
return "SPEED";
|
||||
case 2:
|
||||
return "SLOW";
|
||||
case 3:
|
||||
return "FAST_DIGGING";
|
||||
case 4:
|
||||
return "SLOW_DIGGING";
|
||||
case 5:
|
||||
return "INCREASE_DAMAGE";
|
||||
case 6:
|
||||
return "HEAL";
|
||||
case 7:
|
||||
return "HARM";
|
||||
case 8:
|
||||
return "JUMP";
|
||||
case 9:
|
||||
return "CONFUSION";
|
||||
case 10:
|
||||
return "REGENERATION";
|
||||
case 11:
|
||||
return "DAMAGE_RESISTANCE";
|
||||
case 12:
|
||||
return "FIRE_RESISTANCE";
|
||||
case 13:
|
||||
return "WATER_BREATHING";
|
||||
case 14:
|
||||
return "INVISIBILITY";
|
||||
case 15:
|
||||
return "BLINDNESS";
|
||||
case 16:
|
||||
return "NIGHT_VISION";
|
||||
case 17:
|
||||
return "HUNGER";
|
||||
case 18:
|
||||
return "WEAKNESS";
|
||||
case 19:
|
||||
return "POISON";
|
||||
default:
|
||||
return "UNKNOWN_EFFECT_TYPE_" + handle.id;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInstant() {
|
||||
return handle.b();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user