Commits
Parker Hawke authored and md_5 committed 565a57274a4
1 1 | package org.bukkit.event.entity; |
2 2 | |
3 3 | import org.bukkit.entity.Entity; |
4 4 | import org.bukkit.entity.LivingEntity; |
5 + | import org.bukkit.entity.Player; |
5 6 | import org.bukkit.event.Cancellable; |
6 7 | import org.bukkit.event.HandlerList; |
8 + | import org.bukkit.inventory.EquipmentSlot; |
7 9 | import org.bukkit.inventory.ItemStack; |
8 10 | import org.jetbrains.annotations.NotNull; |
9 11 | import org.jetbrains.annotations.Nullable; |
10 12 | |
11 13 | /** |
12 14 | * Called when a LivingEntity shoots a bow firing an arrow |
13 15 | */ |
14 16 | public class EntityShootBowEvent extends EntityEvent implements Cancellable { |
15 17 | private static final HandlerList handlers = new HandlerList(); |
16 18 | private final ItemStack bow; |
19 + | private final ItemStack consumable; |
17 20 | private Entity projectile; |
21 + | private final EquipmentSlot hand; |
18 22 | private final float force; |
23 + | private boolean consumeItem; |
19 24 | private boolean cancelled; |
20 25 | |
21 - | public EntityShootBowEvent( final LivingEntity shooter, final ItemStack bow, final Entity projectile, final float force) { |
26 + | public EntityShootBowEvent( final LivingEntity shooter, final ItemStack bow, final ItemStack consumable, final Entity projectile, final EquipmentSlot hand, final float force, final boolean consumeItem) { |
22 27 | super(shooter); |
23 28 | this.bow = bow; |
29 + | this.consumable = consumable; |
24 30 | this.projectile = projectile; |
31 + | this.hand = hand; |
25 32 | this.force = force; |
33 + | this.consumeItem = consumeItem; |
26 34 | } |
27 35 | |
28 36 | |
29 37 | |
30 38 | public LivingEntity getEntity() { |
31 39 | return (LivingEntity) entity; |
32 40 | } |
33 41 | |
34 42 | /** |
35 43 | * Gets the bow ItemStack used to fire the arrow. |
36 44 | * |
37 45 | * @return the bow involved in this event |
38 46 | */ |
39 47 | |
40 48 | public ItemStack getBow() { |
41 49 | return bow; |
42 50 | } |
43 51 | |
52 + | /** |
53 + | * Get the ItemStack to be consumed in this event (if any). |
54 + | * |
55 + | * For instance, bows will consume an arrow ItemStack in a player's |
56 + | * inventory. |
57 + | * |
58 + | * @return the consumable item |
59 + | */ |
60 + | |
61 + | public ItemStack getConsumable() { |
62 + | return consumable; |
63 + | } |
64 + | |
44 65 | /** |
45 66 | * Gets the projectile which will be launched by this event |
46 67 | * |
47 68 | * @return the launched projectile |
48 69 | */ |
49 70 | |
50 71 | public Entity getProjectile() { |
51 72 | return projectile; |
52 73 | } |
53 74 | |
54 75 | /** |
55 76 | * Replaces the projectile which will be launched |
56 77 | * |
57 78 | * @param projectile the new projectile |
58 79 | */ |
59 80 | public void setProjectile( Entity projectile) { |
60 81 | this.projectile = projectile; |
61 82 | } |
62 83 | |
84 + | /** |
85 + | * Get the hand from which the bow was shot. |
86 + | * |
87 + | * @return the hand |
88 + | */ |
89 + | |
90 + | public EquipmentSlot getHand() { |
91 + | return hand; |
92 + | } |
93 + | |
63 94 | /** |
64 95 | * Gets the force the arrow was launched with |
65 96 | * |
66 97 | * @return bow shooting force, up to 1.0 |
67 98 | */ |
68 99 | public float getForce() { |
69 100 | return force; |
70 101 | } |
71 102 | |
103 + | /** |
104 + | * Set whether or not the consumable item should be consumed in this event. |
105 + | * |
106 + | * If set to false, it is recommended that a call to |
107 + | * {@link Player#updateInventory()} is made as the client may disagree with |
108 + | * the server's decision to not consume a consumable item. |
109 + | * <p> |
110 + | * This value is ignored for entities where items are not required |
111 + | * (skeletons, pillagers, etc.) or with crossbows (as no item is being |
112 + | * consumed). |
113 + | * |
114 + | * @param consumeItem whether or not to consume the item |
115 + | */ |
116 + | public void setConsumeItem(boolean consumeItem) { |
117 + | this.consumeItem = consumeItem; |
118 + | } |
119 + | |
120 + | /** |
121 + | * Get whether or not the consumable item should be consumed in this event. |
122 + | * |
123 + | * @return true if consumed, false otherwise |
124 + | */ |
125 + | public boolean shouldConsumeItem() { |
126 + | return consumeItem; |
127 + | } |
128 + | |
72 129 | |
73 130 | public boolean isCancelled() { |
74 131 | return cancelled; |
75 132 | } |
76 133 | |
77 134 | |
78 135 | public void setCancelled(boolean cancel) { |
79 136 | cancelled = cancel; |
80 137 | } |
81 138 | |