From 92f50ed8215a1e22aa896d5b166aac73b113e4b7 Mon Sep 17 00:00:00 2001 From: virtualWinter Date: Fri, 21 Jul 2023 06:33:27 +0300 Subject: [PATCH] PotionEffect event updates diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectAddEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectAddEvent.java index 6ac7dc75..6627e6ed 100644 --- a/src/main/java/org/bukkit/event/entity/PotionEffectAddEvent.java +++ b/src/main/java/org/bukkit/event/entity/PotionEffectAddEvent.java @@ -5,16 +5,15 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.bukkit.potion.PotionEffect; -import lombok.Getter; -import lombok.Setter; - - +/** + * Called when a potion effect is applied to an entity, or an existing effect is extended or upgraded + */ public class PotionEffectAddEvent extends PotionEffectEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); - @Getter @Setter private boolean cancelled; - @Getter protected final EffectCause effectCause; + private boolean cancelled; + protected final EffectCause effectCause; public PotionEffectAddEvent(LivingEntity entity, PotionEffect effect, EffectCause effectCause) { super(entity, effect); @@ -30,11 +29,46 @@ public class PotionEffectAddEvent extends PotionEffectEvent implements Cancellab return handlers; } + public EffectCause getCause() { + return effectCause; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + public enum EffectCause { + /** + * Indicates the effect was caused by the proximity of a potion effect splash + */ POTION_SPLASH, + /** + * Indicates the effect was caused by the proximity of a beacon + */ BEACON, + /** + * Indicates the effect was caused by damage from a wither skeleton + */ WITHER_SKELETON, + /** + * Indicates the effect was caused by damage from a wither skull + */ + WITHER_SKULL, + /** + * Indicates the effect was caused by a plugin + */ PLUGIN, + /** + * Indicates the effect was caused by an event not covered by + * this enum + */ UNKNOWN } } \ No newline at end of file diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectEvent.java index aefbc8f8..6510a624 100644 --- a/src/main/java/org/bukkit/event/entity/PotionEffectEvent.java +++ b/src/main/java/org/bukkit/event/entity/PotionEffectEvent.java @@ -3,11 +3,9 @@ package org.bukkit.event.entity; import org.bukkit.entity.LivingEntity; import org.bukkit.potion.PotionEffect; -import lombok.Getter; - public abstract class PotionEffectEvent extends EntityEvent { - @Getter private final PotionEffect effect; + private final PotionEffect effect; public PotionEffectEvent(LivingEntity what, PotionEffect effect) { super(what); @@ -19,5 +17,7 @@ public abstract class PotionEffectEvent extends EntityEvent { return (LivingEntity) super.getEntity(); } - + public PotionEffect getEffect() { + return effect; + } } \ No newline at end of file diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectExpireEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectExpireEvent.java index 2c1e7424..70a92ae4 100644 --- a/src/main/java/org/bukkit/event/entity/PotionEffectExpireEvent.java +++ b/src/main/java/org/bukkit/event/entity/PotionEffectExpireEvent.java @@ -5,14 +5,33 @@ import org.bukkit.potion.PotionEffect; import lombok.Getter; +/** + * Called when a potion effect on an entity runs out. Cancelling the event extends + * the effect with a practically infinite duration. The new duration can also be set + * explicitly by calling {@link #setDuration}. + * + * Handlers of {@link PotionEffectRemoveEvent} will also receive this event. + */ public class PotionEffectExpireEvent extends PotionEffectRemoveEvent { - @Getter private int duration = 0; + private int duration = 0; public PotionEffectExpireEvent(LivingEntity entity, PotionEffect effect) { super(entity, effect); } + + /** + * Get the new duration for the potion effect. This is initially 0. + */ + public int getDuration() { + return duration; + } + + /** + * Set a new duration for the potion effect. Passing 0 to this method un-cancels + * the event, and passing anything above 0 cancels it. + */ public void setDuration(int duration) { this.duration = Math.max(0, duration); } diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectExtendEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectExtendEvent.java index bb25707a..1292c2fb 100644 --- a/src/main/java/org/bukkit/event/entity/PotionEffectExtendEvent.java +++ b/src/main/java/org/bukkit/event/entity/PotionEffectExtendEvent.java @@ -3,14 +3,24 @@ package org.bukkit.event.entity; import org.bukkit.entity.LivingEntity; import org.bukkit.potion.PotionEffect; -import lombok.Getter; - +/** + * Called when an entity's active potion effect is extended or upgraded. + * + * Handlers of {@link PotionEffectAddEvent} will also receive this event. + */ public class PotionEffectExtendEvent extends PotionEffectAddEvent { - @Getter private final PotionEffect oldEffect; + private final PotionEffect oldEffect; public PotionEffectExtendEvent(LivingEntity entity, PotionEffect effect, PotionEffect oldEffect, EffectCause effectCause) { super(entity, effect, effectCause); this.oldEffect = oldEffect; } + + /** + * Get the state of the potion effect prior to the change + */ + public PotionEffect getOldEffect() { + return oldEffect; + } } \ No newline at end of file diff --git a/src/main/java/org/bukkit/event/entity/PotionEffectRemoveEvent.java b/src/main/java/org/bukkit/event/entity/PotionEffectRemoveEvent.java index f2be18e7..9f5bddb7 100644 --- a/src/main/java/org/bukkit/event/entity/PotionEffectRemoveEvent.java +++ b/src/main/java/org/bukkit/event/entity/PotionEffectRemoveEvent.java @@ -8,16 +8,29 @@ import org.bukkit.potion.PotionEffect; import lombok.Getter; import lombok.Setter; +/** + * Called when a potion effect is removed from an entity for whatever reason + */ public class PotionEffectRemoveEvent extends PotionEffectEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); - @Getter @Setter private boolean cancelled; + private boolean cancelled; public PotionEffectRemoveEvent(LivingEntity entity, PotionEffect effect) { super(entity, effect); } + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + @Override public HandlerList getHandlers() { return handlers; -- 2.41.0.windows.1