diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityShootBowEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityShootBowEvent.java index 18c5e31abc..d4d7ad9c3c 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityShootBowEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityShootBowEvent.java @@ -2,8 +2,10 @@ package org.bukkit.event.entity; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,15 +16,21 @@ import org.jetbrains.annotations.Nullable; public class EntityShootBowEvent extends EntityEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final ItemStack bow; + private final ItemStack consumable; private Entity projectile; + private final EquipmentSlot hand; private final float force; + private boolean consumeItem; private boolean cancelled; - public EntityShootBowEvent(@NotNull final LivingEntity shooter, @Nullable final ItemStack bow, @NotNull final Entity projectile, final float force) { + 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) { super(shooter); this.bow = bow; + this.consumable = consumable; this.projectile = projectile; + this.hand = hand; this.force = force; + this.consumeItem = consumeItem; } @NotNull @@ -41,6 +49,19 @@ public class EntityShootBowEvent extends EntityEvent implements Cancellable { return bow; } + /** + * Get the ItemStack to be consumed in this event (if any). + * + * For instance, bows will consume an arrow ItemStack in a player's + * inventory. + * + * @return the consumable item + */ + @Nullable + public ItemStack getConsumable() { + return consumable; + } + /** * Gets the projectile which will be launched by this event * @@ -60,6 +81,16 @@ public class EntityShootBowEvent extends EntityEvent implements Cancellable { this.projectile = projectile; } + /** + * Get the hand from which the bow was shot. + * + * @return the hand + */ + @NotNull + public EquipmentSlot getHand() { + return hand; + } + /** * Gets the force the arrow was launched with * @@ -69,6 +100,32 @@ public class EntityShootBowEvent extends EntityEvent implements Cancellable { return force; } + /** + * Set whether or not the consumable item should be consumed in this event. + * + * If set to false, it is recommended that a call to + * {@link Player#updateInventory()} is made as the client may disagree with + * the server's decision to not consume a consumable item. + *

+ * This value is ignored for entities where items are not required + * (skeletons, pillagers, etc.) or with crossbows (as no item is being + * consumed). + * + * @param consumeItem whether or not to consume the item + */ + public void setConsumeItem(boolean consumeItem) { + this.consumeItem = consumeItem; + } + + /** + * Get whether or not the consumable item should be consumed in this event. + * + * @return true if consumed, false otherwise + */ + public boolean shouldConsumeItem() { + return consumeItem; + } + @Override public boolean isCancelled() { return cancelled;