Commits

Martoph authored and md_5 committed 197d8f3d76f
#577: Add EntityExhaustionEvent
No tags

src/main/java/org/bukkit/event/entity/EntityExhaustionEvent.java

Added
1 +package org.bukkit.event.entity;
2 +
3 +import org.bukkit.entity.HumanEntity;
4 +import org.bukkit.event.Cancellable;
5 +import org.bukkit.event.HandlerList;
6 +import org.jetbrains.annotations.NotNull;
7 +
8 +/**
9 + * Called when a human entity experiences exhaustion.
10 + *
11 + * An exhaustion level greater than 4.0 causes a decrease in saturation by 1.
12 + */
13 +public class EntityExhaustionEvent extends EntityEvent implements Cancellable {
14 +
15 + private static final HandlerList handlers = new HandlerList();
16 + private final ExhaustionReason exhaustionReason;
17 + private float exhaustion;
18 + private boolean cancel;
19 +
20 + public EntityExhaustionEvent(@NotNull HumanEntity who, @NotNull ExhaustionReason exhaustionReason, float exhaustion) {
21 + super(who);
22 + this.exhaustionReason = exhaustionReason;
23 + this.exhaustion = exhaustion;
24 + }
25 +
26 + /**
27 + * Gets the {@link ExhaustionReason} for this event
28 + *
29 + * @return the exhaustion reason
30 + */
31 + @NotNull
32 + public ExhaustionReason getExhaustionReason() {
33 + return exhaustionReason;
34 + }
35 +
36 + /**
37 + * Get the amount of exhaustion to add to the player's current exhaustion.
38 + *
39 + * @return amount of exhaustion
40 + */
41 + public float getExhaustion() {
42 + return exhaustion;
43 + }
44 +
45 + /**
46 + * Set the exhaustion to apply to the player.
47 + *
48 + * The maximum exhaustion that a player can have is 40. No error will be
49 + * thrown if this limit is hit. This value may be negative, but there is
50 + * unknown behavior for when exhaustion is below 0.
51 + *
52 + * @param exhaustion new exhaustion to add
53 + */
54 + public void setExhaustion(float exhaustion) {
55 + this.exhaustion = exhaustion;
56 + }
57 +
58 + @NotNull
59 + @Override
60 + public HumanEntity getEntity() {
61 + return (HumanEntity) super.getEntity();
62 + }
63 +
64 + @Override
65 + public boolean isCancelled() {
66 + return cancel;
67 + }
68 +
69 + @Override
70 + public void setCancelled(boolean cancel) {
71 + this.cancel = cancel;
72 + }
73 +
74 + /**
75 + * The reason for why a PlayerExhaustionEvent takes place
76 + */
77 + public enum ExhaustionReason {
78 +
79 + /**
80 + * Player mines a block
81 + */
82 + BLOCK_MINED,
83 + /**
84 + * Player has the hunger potion effect
85 + */
86 + HUNGER_EFFECT,
87 + /**
88 + * Player takes damage
89 + */
90 + DAMAGED,
91 + /**
92 + * Player attacks another entity
93 + */
94 + ATTACK,
95 + /**
96 + * Player is sprint jumping
97 + */
98 + JUMP_SPRINT,
99 + /**
100 + * Player jumps
101 + */
102 + JUMP,
103 + /**
104 + * Player swims one centimeter
105 + */
106 + SWIM,
107 + /**
108 + * Player walks underwater one centimeter
109 + */
110 + WALK_UNDERWATER,
111 + /**
112 + * Player moves on the surface of water one centimeter
113 + */
114 + WALK_ON_WATER,
115 + /**
116 + * Player sprints one centimeter
117 + */
118 + SPRINT,
119 + /**
120 + * Player crouches one centimeter (does not effect exhaustion, but fires
121 + * nonetheless)
122 + */
123 + CROUCH,
124 + /**
125 + * Player walks one centimeter (does not effect exhaustion, but fires
126 + * nonetheless)
127 + */
128 + WALK,
129 + /**
130 + * Player regenerated health
131 + */
132 + REGEN,
133 + /**
134 + * Unknown exhaustion reason
135 + */
136 + UNKNOWN
137 + }
138 +
139 + @NotNull
140 + @Override
141 + public HandlerList getHandlers() {
142 + return handlers;
143 + }
144 +
145 + @NotNull
146 + public static HandlerList getHandlerList() {
147 + return handlers;
148 + }
149 +}

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut