Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
EntityDamageEvent.java
1 package org.bukkit.event.entity;
2 
3 import org.bukkit.entity.Entity;
7 
8 /**
9  * Stores data for damage events
10  */
11 public class EntityDamageEvent extends EntityEvent implements Cancellable {
12  private static final HandlerList handlers = new HandlerList();
13  private double damage;
14  private boolean cancelled;
15  private final DamageCause cause;
16 
17  @Deprecated
18  public EntityDamageEvent(final Entity damagee, final DamageCause cause, final int damage) {
19  this(damagee, cause, (double) damage);
20  }
21 
22  public EntityDamageEvent(final Entity damagee, final DamageCause cause, final double damage) {
23  super(damagee);
24  this.cause = cause;
25  this.damage = damage;
26  }
27 
28  public boolean isCancelled() {
29  return cancelled;
30  }
31 
32  public void setCancelled(boolean cancel) {
33  cancelled = cancel;
34  }
35 
36  /**
37  * Gets the amount of damage caused by the event
38  *
39  * @return The amount of damage caused by the event
40  */
41  public double getDamage() {
42  return damage;
43  }
44 
45  /**
46  * This method exists for legacy reasons to provide backwards
47  * compatibility. It will not exist at runtime and should not be used
48  * under any circumstances.
49  */
50  @Deprecated
51  public int _INVALID_getDamage() {
52  return NumberConversions.ceil(getDamage());
53  }
54 
55  /**
56  * Sets the amount of damage caused by the event
57  *
58  * @param damage The amount of damage caused by the event
59  */
60  public void setDamage(double damage) {
61  this.damage = damage;
62  }
63 
64  /**
65  * This method exists for legacy reasons to provide backwards
66  * compatibility. It will not exist at runtime and should not be used
67  * under any circumstances.
68  */
69  @Deprecated
70  public void _INVALID_setDamage(int damage) {
71  setDamage(damage);
72  }
73 
74  /**
75  * Gets the cause of the damage.
76  *
77  * @return A DamageCause value detailing the cause of the damage.
78  */
79  public DamageCause getCause() {
80  return cause;
81  }
82 
83  @Override
84  public HandlerList getHandlers() {
85  return handlers;
86  }
87 
88  public static HandlerList getHandlerList() {
89  return handlers;
90  }
91 
92  /**
93  * An enum to specify the cause of the damage
94  */
95  public enum DamageCause {
96 
97  /**
98  * Damage caused when an entity contacts a block such as a Cactus.
99  * <p>
100  * Damage: 1 (Cactus)
101  */
103  /**
104  * Damage caused when an entity attacks another entity.
105  * <p>
106  * Damage: variable
107  */
109  /**
110  * Damage caused when attacked by a projectile.
111  * <p>
112  * Damage: variable
113  */
115  /**
116  * Damage caused by being put in a block
117  * <p>
118  * Damage: 1
119  */
121  /**
122  * Damage caused when an entity falls a distance greater than 3 blocks
123  * <p>
124  * Damage: fall height - 3.0
125  */
127  /**
128  * Damage caused by direct exposure to fire
129  * <p>
130  * Damage: 1
131  */
133  /**
134  * Damage caused due to burns caused by fire
135  * <p>
136  * Damage: 1
137  */
139  /**
140  * Damage caused due to a snowman melting
141  * <p>
142  * Damage: 1
143  */
145  /**
146  * Damage caused by direct exposure to lava
147  * <p>
148  * Damage: 4
149  */
151  /**
152  * Damage caused by running out of air while in water
153  * <p>
154  * Damage: 2
155  */
157  /**
158  * Damage caused by being in the area when a block explodes.
159  * <p>
160  * Damage: variable
161  */
163  /**
164  * Damage caused by being in the area when an entity, such as a
165  * Creeper, explodes.
166  * <p>
167  * Damage: variable
168  */
170  /**
171  * Damage caused by falling into the void
172  * <p>
173  * Damage: 4 for players
174  */
176  /**
177  * Damage caused by being struck by lightning
178  * <p>
179  * Damage: 5
180  */
182  /**
183  * Damage caused by committing suicide using the command "/kill"
184  * <p>
185  * Damage: 1000
186  */
188  /**
189  * Damage caused by starving due to having an empty hunger bar
190  * <p>
191  * Damage: 1
192  */
194  /**
195  * Damage caused due to an ongoing poison effect
196  * <p>
197  * Damage: 1
198  */
200  /**
201  * Damage caused by being hit by a damage potion or spell
202  * <p>
203  * Damage: variable
204  */
206  /**
207  * Damage caused by Wither potion effect
208  */
210  /**
211  * Damage caused by being hit by a falling block which deals damage
212  * <p>
213  * <b>Note:</b> Not every block deals damage
214  * <p>
215  * Damage: variable
216  */
218  /**
219  * Damage caused in retaliation to another attack by the Thorns
220  * enchantment.
221  * <p>
222  * Damage: 1-4 (Thorns)
223  */
225  /**
226  * Custom damage.
227  * <p>
228  * Damage: variable
229  */
230  CUSTOM
231  }
232 }