Commits
Cynthia Yantis authored and md_5 committed ece4a912915
1 + | package org.bukkit.event.entity; |
2 + | |
3 + | import org.bukkit.entity.LivingEntity; |
4 + | import org.bukkit.event.HandlerList; |
5 + | import org.bukkit.inventory.EquipmentSlot; |
6 + | import org.bukkit.inventory.ItemStack; |
7 + | import org.jetbrains.annotations.NotNull; |
8 + | |
9 + | /** |
10 + | * Called when an entity equips, removes, switches or breaks armor, or when an |
11 + | * entity is spawned. For example: |
12 + | * <ul> |
13 + | * <li>A player equips a chestplate by right clicking</li> |
14 + | * <li>An entity is naturally spawned (an event called for each piece of |
15 + | * armor)</li> |
16 + | * <li>A zombie's helmet is broken due to sunlight</li> |
17 + | * </ul> |
18 + | * |
19 + | * Note that this does NOT get called for things such as |
20 + | * {@link PlayerDeathEvent}, where the entity loses armor due to dying. |
21 + | */ |
22 + | public class EntityArmorChangeEvent extends EntityEvent { |
23 + | |
24 + | private static final HandlerList handlers = new HandlerList(); |
25 + | // |
26 + | private final ItemStack oldArmor; |
27 + | private final ItemStack newArmor; |
28 + | private final EquipmentSlot equipmentSlot; |
29 + | private final ChangeReason changeReason; |
30 + | |
31 + | public EntityArmorChangeEvent( LivingEntity entity, ItemStack oldArmor, ItemStack newArmor, EquipmentSlot equipmentSlot, ChangeReason changeReason) { |
32 + | super(entity); |
33 + | this.oldArmor = oldArmor; |
34 + | this.newArmor = newArmor; |
35 + | this.equipmentSlot = equipmentSlot; |
36 + | this.changeReason = changeReason; |
37 + | } |
38 + | |
39 + | /** |
40 + | * Gets the itemstack that was the old armor equipped. |
41 + | * |
42 + | * The material will be AIR if there wasn't an old armor piece |
43 + | * |
44 + | * @return The old armor that was equipped |
45 + | */ |
46 + | |
47 + | public ItemStack getOldArmor() { |
48 + | return oldArmor.clone(); |
49 + | } |
50 + | |
51 + | /** |
52 + | * Gets the itemstack that is the new armor equipped. |
53 + | * |
54 + | * The material will be AIR if there wasn't a new armor piece |
55 + | * |
56 + | * @return The new armor that is equipped |
57 + | */ |
58 + | |
59 + | public ItemStack getNewArmor() { |
60 + | return newArmor.clone(); |
61 + | } |
62 + | |
63 + | /** |
64 + | * Gets the slot that had armor modified. |
65 + | * |
66 + | * @return The EquipmentSlot that was modified by this event |
67 + | */ |
68 + | |
69 + | public EquipmentSlot getEquipmentSlot() { |
70 + | return equipmentSlot; |
71 + | } |
72 + | |
73 + | /** |
74 + | * Gets the reason this event was fired. |
75 + | * |
76 + | * @return An enum value representing the cause of the event |
77 + | * @see ChangeReason |
78 + | */ |
79 + | |
80 + | public ChangeReason getChangeReason() { |
81 + | return changeReason; |
82 + | } |
83 + | |
84 + | |
85 + | |
86 + | public LivingEntity getEntity() { |
87 + | return (LivingEntity) entity; |
88 + | } |
89 + | |
90 + | |
91 + | |
92 + | public HandlerList getHandlers() { |
93 + | return handlers; |
94 + | } |
95 + | |
96 + | |
97 + | public static HandlerList getHandlerList() { |
98 + | return handlers; |
99 + | } |
100 + | |
101 + | /** |
102 + | * Represents the various causes of the event. |
103 + | */ |
104 + | public enum ChangeReason { |
105 + | |
106 + | /** |
107 + | * Represented the event being called due to armor breaking. |
108 + | */ |
109 + | BREAK, |
110 + | /** |
111 + | * Represented the event being called due to armor being equipped. |
112 + | */ |
113 + | EQUIP, |
114 + | /** |
115 + | * Represented the event being called due to two armor pieces being |
116 + | * swapped. |
117 + | */ |
118 + | SWITCH, |
119 + | /** |
120 + | * Represented the event being called due to armor being removed. |
121 + | */ |
122 + | UNEQUIP |
123 + | } |
124 + | } |