From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: JRoy Date: Wed, 7 Oct 2020 12:04:17 -0400 Subject: [PATCH] Add EntityLoadCrossbowEvent diff --git a/src/main/java/io/papermc/paper/event/entity/EntityLoadCrossbowEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityLoadCrossbowEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..f7631a5ac0f2ccfa6b81bea9ab54b30fbb3278dd --- /dev/null +++ b/src/main/java/io/papermc/paper/event/entity/EntityLoadCrossbowEvent.java @@ -0,0 +1,92 @@ +package io.papermc.paper.event.entity; + +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; + +/** + * Called when a LivingEntity loads a crossbow with a projectile. + */ +@NullMarked +public class EntityLoadCrossbowEvent extends EntityEvent implements Cancellable { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final ItemStack crossbow; + private final EquipmentSlot hand; + + private boolean consumeItem = true; + private boolean cancelled; + + @ApiStatus.Internal + public EntityLoadCrossbowEvent(final LivingEntity entity, final ItemStack crossbow, final EquipmentSlot hand) { + super(entity); + this.crossbow = crossbow; + this.hand = hand; + } + + @Override + public LivingEntity getEntity() { + return (LivingEntity) super.getEntity(); + } + + /** + * Gets the crossbow {@link ItemStack} being loaded. + * + * @return the crossbow involved in this event + */ + public ItemStack getCrossbow() { + return this.crossbow; + } + + /** + * Gets the hand from which the crossbow was loaded. + * + * @return the hand + */ + public EquipmentSlot getHand() { + return this.hand; + } + + /** + * @return should the itemstack be consumed + */ + public boolean shouldConsumeItem() { + return this.consumeItem; + } + + /** + * @param consume should the item be consumed + */ + public void setConsumeItem(final boolean consume) { + this.consumeItem = consume; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + /** + * Set whether to cancel the crossbow being loaded. If canceled, the + * projectile that would be loaded into the crossbow will not be consumed. + */ + @Override + public void setCancelled(final boolean cancel) { + this.cancelled = cancel; + } + + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +}