-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathDamageable.java
More file actions
141 lines (126 loc) · 4.26 KB
/
Damageable.java
File metadata and controls
141 lines (126 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package org.bukkit.entity;
import org.bukkit.attribute.Attribute;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
/**
* Represents an {@link Entity} that has health and can take damage.
*/
@NullMarked
public interface Damageable extends Entity {
/**
* Deals the given amount of damage to this entity.
*
* @param amount Amount of damage to deal
*/
void damage(double amount);
/**
* Deals the given amount of damage to this entity from a specified
* {@link Entity}.
*
* @param amount amount of damage to deal
* @param source entity to which the damage should be attributed
*/
void damage(double amount, @Nullable Entity source);
/**
* Deals the given amount of damage to this entity from a specified
* {@link DamageSource}.
*
* @param amount amount of damage to deal
* @param damageSource source to which the damage should be attributed
*/
void damage(double amount, DamageSource damageSource);
/**
* Sets the entity's health to 0 and kill the entity with a generic DamageSource.
*
* @throws IllegalStateException if is used in world generation
*/
default void kill() {
this.kill(DamageSource.builder(DamageType.GENERIC_KILL).build());
}
/**
* Sets the entity's health to 0 and kill the entity with the specified DamageSource.
*
* @param damageSource the DamageSource to use for the kill
* @throws IllegalStateException if is used in world generation
*/
void kill(DamageSource damageSource);
/**
* Gets the entity's health from 0 to {@link #getMaxHealth()}, where 0 is dead.
*
* @return Health represented from 0 to max
*/
double getHealth();
/**
* Sets the entity's health from 0 to {@link #getMaxHealth()}, where 0 is
* dead.
*
* @param health New health represented from 0 to max
* @throws IllegalArgumentException Thrown if the health is {@literal < 0 or >}
* {@link #getMaxHealth()}
*/
void setHealth(double health);
/**
* Heal this entity by the given amount. This will call {@link org.bukkit.event.entity.EntityRegainHealthEvent}.
*
* @param amount heal amount
*/
default void heal(final double amount) {
this.heal(amount, EntityRegainHealthEvent.RegainReason.CUSTOM);
}
/**
* Heal this entity by the given amount. This will call {@link org.bukkit.event.entity.EntityRegainHealthEvent}.
*
* @param amount heal amount
* @param reason heal reason
*/
void heal(double amount, EntityRegainHealthEvent.RegainReason reason);
/**
* Gets the entity's absorption amount.
*
* @return absorption amount from 0
*/
double getAbsorptionAmount();
/**
* Sets the entity's absorption amount.
* <p>
* Note: The amount is capped to the value of
* {@link Attribute#MAX_ABSORPTION}. The effect of this method on
* that attribute is currently unspecified and subject to change.
*
* @param amount new absorption amount from 0
* @throws IllegalArgumentException thrown if health is {@literal < 0} or
* non-finite.
*/
void setAbsorptionAmount(double amount);
/**
* Gets the maximum health this entity has.
*
* @return Maximum health
* @deprecated use {@link Attribute#MAX_HEALTH}.
*/
@Deprecated(since = "1.11")
double getMaxHealth();
/**
* Sets the maximum health this entity can have.
* <p>
* If the health of the entity is above the value provided it will be set
* to that value.
* <p>
* Note: An entity with a health bar ({@link Player}, {@link EnderDragon},
* {@link Wither}, etc...) will have their bar scaled accordingly.
*
* @param health amount of health to set the maximum to
* @deprecated use {@link Attribute#MAX_HEALTH}.
*/
@Deprecated(since = "1.11")
void setMaxHealth(double health);
/**
* Resets the max health to the original amount.
* @deprecated use {@link Attribute#MAX_HEALTH}.
*/
@Deprecated(since = "1.11")
void resetMaxHealth();
}