Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PotionSplashEvent.java
1 package org.bukkit.event.entity;
2 
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Map;
6 
7 import org.apache.commons.lang.Validate;
12 
13 /**
14  * Called when a splash potion hits an area
15  */
16 public class PotionSplashEvent extends ProjectileHitEvent implements Cancellable {
17  private static final HandlerList handlers = new HandlerList();
18  private boolean cancelled;
19  private final Map<LivingEntity, Double> affectedEntities;
20 
21  public PotionSplashEvent(final ThrownPotion potion, final Map<LivingEntity, Double> affectedEntities) {
22  super(potion);
23 
24  this.affectedEntities = affectedEntities;
25  }
26 
27  @Override
28  public ThrownPotion getEntity() {
29  return (ThrownPotion) entity;
30  }
31 
32  /**
33  * Gets the potion which caused this event
34  *
35  * @return The thrown potion entity
36  */
38  return (ThrownPotion) getEntity();
39  }
40 
41  /**
42  * Retrieves a list of all effected entities
43  *
44  * @return A fresh copy of the affected entity list
45  */
46  public Collection<LivingEntity> getAffectedEntities() {
47  return new ArrayList<LivingEntity>(affectedEntities.keySet());
48  }
49 
50  /**
51  * Gets the intensity of the potion's effects for given entity; This
52  * depends on the distance to the impact center
53  *
54  * @param entity Which entity to get intensity for
55  * @return intensity relative to maximum effect; 0.0: not affected; 1.0:
56  * fully hit by potion effects
57  */
58  public double getIntensity(LivingEntity entity) {
59  Double intensity = affectedEntities.get(entity);
60  return intensity != null ? intensity : 0.0;
61  }
62 
63  /**
64  * Overwrites the intensity for a given entity
65  *
66  * @param entity For which entity to define a new intensity
67  * @param intensity relative to maximum effect
68  */
69  public void setIntensity(LivingEntity entity, double intensity) {
70  Validate.notNull(entity, "You must specify a valid entity.");
71  if (intensity <= 0.0) {
72  affectedEntities.remove(entity);
73  } else {
74  affectedEntities.put(entity, Math.min(intensity, 1.0));
75  }
76  }
77 
78  public boolean isCancelled() {
79  return cancelled;
80  }
81 
82  public void setCancelled(boolean cancel) {
83  cancelled = cancel;
84  }
85 
86  @Override
87  public HandlerList getHandlers() {
88  return handlers;
89  }
90 
91  public static HandlerList getHandlerList() {
92  return handlers;
93  }
94 }
Collection< LivingEntity > getAffectedEntities()
void setIntensity(LivingEntity entity, double intensity)