From abee107830009bd2a7445fe1a564d186b515564b Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 17 Dec 2012 09:45:30 +0100 Subject: Add ability to modify ThrownPotion properties. Adds BUKKIT-3197 --- .../java/net/minecraft/server/EntityPotion.java | 2 +- .../craftbukkit/entity/CraftThrownPotion.java | 30 +++++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main/java/net/minecraft/server/EntityPotion.java b/src/main/java/net/minecraft/server/EntityPotion.java index ac570b65..e391ea6f 100644 --- a/src/main/java/net/minecraft/server/EntityPotion.java +++ b/src/main/java/net/minecraft/server/EntityPotion.java @@ -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); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java index ea6b107c..97d266fc 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java @@ -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 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 getEffects() { - if (effects == null) { - effects = Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionValue()); - } + return Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionValue()); + } + + 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() + "."); - return effects; + getHandle().c = CraftItemStack.asNMSCopy(item); } @Override -- cgit v1.2.3