summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZeerix <zeerix@draig.de>2012-01-20 08:16:45 +0100
committerEvilSeph <evilseph@gmail.com>2012-01-24 02:11:38 -0500
commitb516d3bf78ea2f2bef75a6f15293bf83630dcfa5 (patch)
treeff8dcf2f92fefa4119e8bda63378c56ee236f0b3 /src
parent8d19709c5a5ba14b945e30c86bdc13a7edc13c3e (diff)
downloadbukkit-b516d3bf78ea2f2bef75a6f15293bf83630dcfa5.tar
bukkit-b516d3bf78ea2f2bef75a6f15293bf83630dcfa5.tar.gz
bukkit-b516d3bf78ea2f2bef75a6f15293bf83630dcfa5.tar.lz
bukkit-b516d3bf78ea2f2bef75a6f15293bf83630dcfa5.tar.xz
bukkit-b516d3bf78ea2f2bef75a6f15293bf83630dcfa5.zip
[Bleeding] Added PotionSplashEvent for splash potions. Closes BUKKIT-307
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/event/Event.java6
-rw-r--r--src/main/java/org/bukkit/event/entity/PotionSplashEvent.java89
-rw-r--r--src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java4
3 files changed, 99 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java
index af614c41..8a5035d8 100644
--- a/src/main/java/org/bukkit/event/Event.java
+++ b/src/main/java/org/bukkit/event/Event.java
@@ -796,6 +796,12 @@ public abstract class Event implements Serializable {
*/
PROJECTILE_HIT(Category.ENTITY, ProjectileHitEvent.class),
/**
+ * Called when a splash potion hits an area
+ *
+ * @see org.bukkit.event.entity.PotionSplashEvent
+ */
+ POTION_SPLASH(Category.ENTITY, PotionSplashEvent.class),
+ /**
* Called when a Slime splits into smaller Slimes upon death
*
* @see org.bukkit.event.entity.SlimeSplitEvent
diff --git a/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java b/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java
new file mode 100644
index 00000000..9461181e
--- /dev/null
+++ b/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java
@@ -0,0 +1,89 @@
+package org.bukkit.event.entity;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.commons.lang.Validate;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.ThrownPotion;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+
+/**
+ * Called when a splash potion hits an area
+ */
+@SuppressWarnings("serial")
+public class PotionSplashEvent extends ProjectileHitEvent implements Cancellable {
+ private static final HandlerList handlers = new HandlerList();
+ private boolean cancelled;
+ private Map<LivingEntity, Double> affectedEntities;
+
+ public PotionSplashEvent(ThrownPotion potion, Map<LivingEntity, Double> affectedEntities) {
+ super(Type.POTION_SPLASH, potion);
+
+ this.affectedEntities = affectedEntities;
+ }
+
+ /**
+ * Gets the potion which caused this event
+ *
+ * @return The thrown potion entity
+ */
+ public ThrownPotion getPotion() {
+ return (ThrownPotion) getEntity();
+ }
+
+ /**
+ * Retrieves a list of all effected entities
+ *
+ * @return A fresh copy of the affected entity list
+ */
+ public Collection<LivingEntity> getAffectedEntities() {
+ return new ArrayList<LivingEntity>(affectedEntities.keySet());
+ }
+
+ /**
+ * Gets the intensity of the potion's effects for given entity;
+ * This depends on the distance to the impact center
+ *
+ * @param entity Which entity to get intensity for
+ * @return intensity relative to maximum effect; 0.0: not affected; 1.0: fully hit by potion effects
+ */
+ public double getIntensity(LivingEntity entity) {
+ Double intensity = affectedEntities.get(entity);
+ return intensity != null ? intensity : 0.0;
+ }
+
+ /**
+ * Overwrites the intensity for a given entity
+ *
+ * @param entity For which entity to define a new intensity
+ * @param intensity relative to maximum effect
+ */
+ public void setIntensity(LivingEntity entity, double intensity) {
+ Validate.notNull(entity, "You must specify a valid entity.");
+ if (intensity <= 0.0) {
+ affectedEntities.remove(entity);
+ } else {
+ affectedEntities.put(entity, Math.min(intensity, 1.0));
+ }
+ }
+
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ public void setCancelled(boolean cancel) {
+ cancelled = cancel;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
diff --git a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
index c019e586..37a99885 100644
--- a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
+++ b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
@@ -14,6 +14,10 @@ public class ProjectileHitEvent extends EntityEvent {
super(Type.PROJECTILE_HIT, projectile);
}
+ public ProjectileHitEvent(Type type, Projectile projectile) {
+ super(type, projectile);
+ }
+
@Override
public HandlerList getHandlers() {
return handlers;