From dcad73811ea93c549ae9601ce9b3e250d9df83cd Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Wed, 2 Sep 2020 18:52:37 +1000 Subject: [PATCH] #519: Add ArrowBodyCountChangeEvent By: Martoph --- .../java/org/bukkit/entity/LivingEntity.java | 28 ++++++ .../entity/ArrowBodyCountChangeEvent.java | 87 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/ArrowBodyCountChangeEvent.java diff --git a/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java b/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java index dd6eff5cc5..468a5e13fa 100644 --- a/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java +++ b/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java @@ -192,6 +192,34 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource */ public void setMaximumAir(int ticks); + /** + * Gets the time in ticks until the next arrow leaves the entity's body. + * + * @return ticks until arrow leaves + */ + public int getArrowCooldown(); + + /** + * Sets the time in ticks until the next arrow leaves the entity's body. + * + * @param ticks time until arrow leaves + */ + public void setArrowCooldown(int ticks); + + /** + * Gets the amount of arrows in an entity's body. + * + * @return amount of arrows in body + */ + public int getArrowsInBody(); + + /** + * Set the amount of arrows in the entity's body. + * + * @param count amount of arrows in entity's body + */ + public void setArrowsInBody(int count); + /** * Returns the living entity's current maximum no damage ticks. *

diff --git a/paper-api/src/main/java/org/bukkit/event/entity/ArrowBodyCountChangeEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/ArrowBodyCountChangeEvent.java new file mode 100644 index 0000000000..96ce136ba2 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/ArrowBodyCountChangeEvent.java @@ -0,0 +1,87 @@ +package org.bukkit.event.entity; + +import com.google.common.base.Preconditions; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * Called when an arrow enters or exists an entity's body. + */ +public class ArrowBodyCountChangeEvent extends EntityEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + // + private boolean cancelled; + private final boolean isReset; + private final int oldAmount; + private int newAmount; + + public ArrowBodyCountChangeEvent(@NotNull LivingEntity entity, int oldAmount, int newAmount, boolean isReset) { + super(entity); + + this.oldAmount = oldAmount; + this.newAmount = newAmount; + this.isReset = isReset; + } + + /** + * Whether the event was called because the entity was reset. + * + * @return was reset + */ + public boolean isReset() { + return isReset; + } + + /** + * Gets the old amount of arrows in the entity's body. + * + * @return amount of arrows + */ + public int getOldAmount() { + return oldAmount; + } + + /** + * Get the new amount of arrows in the entity's body. + * + * @return amount of arrows + */ + public int getNewAmount() { + return newAmount; + } + + /** + * Sets the final amount of arrows in the entity's body. + * + * @param newAmount amount of arrows + */ + public void setNewAmount(int newAmount) { + Preconditions.checkArgument(newAmount >= 0, "New arrow amount must be >= 0"); + this.newAmount = newAmount; + } + + @Override + @NotNull + public LivingEntity getEntity() { + return (LivingEntity) entity; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Override + @NotNull + public HandlerList getHandlers() { + return handlers; + } +}