#533: Add consumed item, hand and consumeItem boolean to EntityShootBowEvent

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
Bukkit/Spigot 2020-08-31 18:39:04 +10:00
parent aee1e203cd
commit 394a95bb69

View File

@ -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.
* <p>
* 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;