summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorOlof Larsson <olof@sylt.nu>2012-12-17 09:45:30 +0100
committerGJ <gjmcferrin@gmail.com>2013-03-21 15:18:27 -0400
commitabee107830009bd2a7445fe1a564d186b515564b (patch)
treed633572baa25a3da931554eb51cd585c884667f8 /src/main/java/org
parent2c5b2a8f6f8f1a9a49cfa546191fadad7da929a5 (diff)
downloadcraftbukkit-abee107830009bd2a7445fe1a564d186b515564b.tar
craftbukkit-abee107830009bd2a7445fe1a564d186b515564b.tar.gz
craftbukkit-abee107830009bd2a7445fe1a564d186b515564b.tar.lz
craftbukkit-abee107830009bd2a7445fe1a564d186b515564b.tar.xz
craftbukkit-abee107830009bd2a7445fe1a564d186b515564b.zip
Add ability to modify ThrownPotion properties. Adds BUKKIT-3197
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java30
1 files changed, 23 insertions, 7 deletions
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<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());
+ }
+
+ 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