|
| 1 | +package io.papermc.paper.event.entity; |
| 2 | + |
| 3 | +import org.bukkit.entity.LivingEntity; |
| 4 | +import org.bukkit.event.Cancellable; |
| 5 | +import org.bukkit.event.HandlerList; |
| 6 | +import org.bukkit.event.entity.EntityEvent; |
| 7 | +import org.jetbrains.annotations.ApiStatus; |
| 8 | +import org.jspecify.annotations.NullMarked; |
| 9 | + |
| 10 | +/** |
| 11 | + * Called when a living entity tries to lunge with a spear |
| 12 | + */ |
| 13 | +@NullMarked |
| 14 | +public class EntityLungeEvent extends EntityEvent implements Cancellable { |
| 15 | + |
| 16 | + private static final HandlerList HANDLER_LIST = new HandlerList(); |
| 17 | + |
| 18 | + private int lungePower; |
| 19 | + private boolean cancelled; |
| 20 | + |
| 21 | + @ApiStatus.Internal |
| 22 | + public EntityLungeEvent(final LivingEntity entity, int lungePower) { |
| 23 | + super(entity); |
| 24 | + this.lungePower = lungePower; |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Gets the lunge power, which when initially passed, matches the enchantment level of the item, but can be higher. |
| 29 | + * |
| 30 | + * @return the lunge power |
| 31 | + */ |
| 32 | + public int getLungePower() { |
| 33 | + return lungePower; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Sets the lunge power. This commonly matches the enchantment level of the item, and can be set higher. |
| 38 | + * <p> |
| 39 | + * If set higher than 3, the power of the lunge will continue to scale like normal, as if the max enchantment |
| 40 | + * level is higher. |
| 41 | + * @param lungePower the new lunge power |
| 42 | + */ |
| 43 | + public void setLungePower(final int lungePower) { |
| 44 | + this.lungePower = lungePower; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public boolean isCancelled() { |
| 49 | + return cancelled; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Set whether to cancel the lunge. If cancelled, the living entity will not lunge forward. |
| 54 | + * @param cancel {@code true} if you wish to cancel this event |
| 55 | + */ |
| 56 | + @Override |
| 57 | + public void setCancelled(final boolean cancel) { |
| 58 | + this.cancelled = cancel; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public HandlerList getHandlers() { |
| 63 | + return HANDLER_LIST; |
| 64 | + } |
| 65 | + |
| 66 | + public static HandlerList getHandlerList() { |
| 67 | + return HANDLER_LIST; |
| 68 | + } |
| 69 | +} |
0 commit comments