Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
EntityRegainHealthEvent.java
1 package org.bukkit.event.entity;
2 
3 import org.bukkit.entity.Entity;
7 
8 /**
9  * Stores data for health-regain events
10  */
11 public class EntityRegainHealthEvent extends EntityEvent implements Cancellable {
12  private static final HandlerList handlers = new HandlerList();
13  private boolean cancelled;
14  private double amount;
15  private final RegainReason regainReason;
16 
17  @Deprecated
18  public EntityRegainHealthEvent(final Entity entity, final int amount, final RegainReason regainReason) {
19  this(entity, (double) amount, regainReason);
20  }
21 
22  public EntityRegainHealthEvent(final Entity entity, final double amount, final RegainReason regainReason) {
23  super(entity);
24  this.amount = amount;
25  this.regainReason = regainReason;
26  }
27 
28  /**
29  * Gets the amount of regained health
30  *
31  * @return The amount of health regained
32  */
33  public double getAmount() {
34  return amount;
35  }
36 
37  /**
38  * This method exists for legacy reasons to provide backwards
39  * compatibility. It will not exist at runtime and should not be used
40  * under any circumstances.
41  */
42  @Deprecated
43  public int _INVALID_getAmount() {
44  return NumberConversions.ceil(getAmount());
45  }
46 
47  /**
48  * Sets the amount of regained health
49  *
50  * @param amount the amount of health the entity will regain
51  */
52  public void setAmount(double amount) {
53  this.amount = amount;
54  }
55 
56  /**
57  * This method exists for legacy reasons to provide backwards
58  * compatibility. It will not exist at runtime and should not be used
59  * under any circumstances.
60  */
61  @Deprecated
62  public void _INVALID_setAmount(int amount) {
63  setAmount(amount);
64  }
65 
66  public boolean isCancelled() {
67  return cancelled;
68  }
69 
70  public void setCancelled(boolean cancel) {
71  cancelled = cancel;
72  }
73 
74  /**
75  * Gets the reason for why the entity is regaining health
76  *
77  * @return A RegainReason detailing the reason for the entity regaining
78  * health
79  */
81  return regainReason;
82  }
83 
84  @Override
85  public HandlerList getHandlers() {
86  return handlers;
87  }
88 
89  public static HandlerList getHandlerList() {
90  return handlers;
91  }
92 
93  /**
94  * An enum to specify the type of health regaining that is occurring
95  */
96  public enum RegainReason {
97 
98  /**
99  * When a player regains health from regenerating due to Peaceful mode
100  * (difficulty=0)
101  */
103  /**
104  * When a player regains health from regenerating due to their hunger
105  * being satisfied
106  */
108  /**
109  * When a player regains health from eating consumables
110  */
112  /**
113  * When an ender dragon regains health from an ender crystal
114  */
116  /**
117  * When a player is healed by a potion or spell
118  */
120  /**
121  * When a player is healed over time by a potion or spell
122  */
124  /**
125  * When a wither is filling its health during spawning
126  */
128  /**
129  * When an entity is damaged by the Wither potion effect
130  */
132  /**
133  * Any other reason not covered by the reasons above
134  */
135  CUSTOM
136  }
137 }