Add ability to modify ThrownPotion properties. Adds BUKKIT-3197

This commit is contained in:
Olof Larsson 2012-12-17 09:45:30 +01:00 committed by GJ
parent 2c5b2a8f6f
commit abee107830
2 changed files with 24 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import org.bukkit.entity.LivingEntity;
public class EntityPotion extends EntityProjectile {
private ItemStack c;
public ItemStack c; // CraftBukkit private --> public
public EntityPotion(World world) {
super(world);

View File

@ -4,26 +4,42 @@ import java.util.Collection;
import net.minecraft.server.EntityPotion;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionEffect;
public class CraftThrownPotion extends CraftProjectile implements ThrownPotion {
private Collection<PotionEffect> effects = null;
public CraftThrownPotion(CraftServer server, EntityPotion entity) {
super(server, entity);
}
// TODO: This one does not handle custom NBT potion effects does it?
// In that case this method could be said to be misleading or incorrect
public Collection<PotionEffect> getEffects() {
if (effects == null) {
effects = Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionValue());
}
return Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionValue());
}
return effects;
public ItemStack getItem() {
// We run this method once since it will set the item stack if there is none.
getHandle().getPotionValue();
return CraftItemStack.asBukkitCopy(getHandle().c);
}
public void setItem(ItemStack item) {
// The ItemStack must not be null.
Validate.notNull(item, "ItemStack cannot be null.");
// The ItemStack must be a potion.
Validate.isTrue(item.getType() == Material.POTION, "ItemStack must be a potion. This item stack was " + item.getType() + ".");
getHandle().c = CraftItemStack.asNMSCopy(item);
}
@Override