Commits

Parker Hawke authored and md_5 committed 565a57274a4
#533: Add consumed item, hand and consumeItem boolean to EntityShootBowEvent
No tags

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

Modified
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(@NotNull final LivingEntity shooter, @Nullable final ItemStack bow, @NotNull final Entity projectile, final float force) {
26 + public EntityShootBowEvent(@NotNull final LivingEntity shooter, @Nullable final ItemStack bow, @Nullable final ItemStack consumable, @NotNull final Entity projectile, @NotNull 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 @NotNull
29 37 @Override
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 @Nullable
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 + @Nullable
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 @NotNull
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(@NotNull 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 + @NotNull
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 @Override
73 130 public boolean isCancelled() {
74 131 return cancelled;
75 132 }
76 133
77 134 @Override
78 135 public void setCancelled(boolean cancel) {
79 136 cancelled = cancel;
80 137 }
81 138

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

Add shortcut