--- a/net/minecraft/world/effect/MobEffectUtil.java
+++ b/net/minecraft/world/effect/MobEffectUtil.java
@@ -13,11 +13,15 @@
 import net.minecraft.world.phys.Vec3;
 
 public final class MobEffectUtil {
+
+    public MobEffectUtil() {}
+
     public static Component formatDuration(MobEffectInstance effect, float multiplier, float tickRate) {
         if (effect.isInfiniteDuration()) {
             return Component.translatable("effect.duration.infinite");
         } else {
-            int i = Mth.floor((float)effect.getDuration() * multiplier);
+            int i = Mth.floor((float) effect.getDuration() * multiplier);
+
             return Component.literal(StringUtil.formatTickDuration(i, tickRate));
         }
     }
@@ -29,6 +33,7 @@
     public static int getDigSpeedAmplification(LivingEntity entity) {
         int i = 0;
         int j = 0;
+
         if (entity.hasEffect(MobEffects.DIG_SPEED)) {
             i = entity.getEffect(MobEffects.DIG_SPEED).getAmplifier();
         }
@@ -44,21 +49,34 @@
         return entity.hasEffect(MobEffects.WATER_BREATHING) || entity.hasEffect(MobEffects.CONDUIT_POWER);
     }
 
-    public static List<ServerPlayer> addEffectToPlayersAround(
-        ServerLevel world, @Nullable Entity entity, Vec3 origin, double range, MobEffectInstance statusEffectInstance, int duration
-    ) {
-        Holder<MobEffect> holder = statusEffectInstance.getEffect();
-        List<ServerPlayer> list = world.getPlayers(
-            player -> player.gameMode.isSurvival()
-                    && (entity == null || !entity.isAlliedTo(player))
-                    && origin.closerThan(player.position(), range)
-                    && (
-                        !player.hasEffect(holder)
-                            || player.getEffect(holder).getAmplifier() < statusEffectInstance.getAmplifier()
-                            || player.getEffect(holder).endsWithin(duration - 1)
-                    )
-        );
-        list.forEach(player -> player.addEffect(new MobEffectInstance(statusEffectInstance), entity));
+    public static List<ServerPlayer> addEffectToPlayersAround(ServerLevel world, @Nullable Entity entity, Vec3 origin, double range, MobEffectInstance statusEffectInstance, int duration) {
+        // CraftBukkit start
+        return MobEffectUtil.addEffectToPlayersAround(world, entity, origin, range, statusEffectInstance, duration, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
+    }
+
+    public static List<ServerPlayer> addEffectToPlayersAround(ServerLevel worldserver, @Nullable Entity entity, Vec3 vec3d, double d0, MobEffectInstance mobeffect, int i, org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause) {
+        // Paper start - Add ElderGuardianAppearanceEvent
+        return addEffectToPlayersAround(worldserver, entity, vec3d, d0, mobeffect, i, cause, null);
+    }
+
+    public static List<ServerPlayer> addEffectToPlayersAround(ServerLevel worldserver, @Nullable Entity entity, Vec3 vec3d, double d0, MobEffectInstance mobeffect, int i, org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause, @Nullable java.util.function.Predicate<ServerPlayer> playerPredicate) {
+        // Paper end - Add ElderGuardianAppearanceEvent
+        // CraftBukkit end
+        Holder<MobEffect> holder = mobeffect.getEffect();
+        List<ServerPlayer> list = worldserver.getPlayers((entityplayer) -> {
+            // Paper start - Add ElderGuardianAppearanceEvent
+            boolean condition = entityplayer.gameMode.isSurvival() && (entity == null || !entity.isAlliedTo((Entity) entityplayer)) && vec3d.closerThan(entityplayer.position(), d0) && (!entityplayer.hasEffect(holder) || entityplayer.getEffect(holder).getAmplifier() < mobeffect.getAmplifier() || entityplayer.getEffect(holder).endsWithin(i - 1));
+            if (condition) {
+                return playerPredicate == null || playerPredicate.test(entityplayer); // Only test the player AFTER it is true
+            } else {
+                return false;
+            }
+            // Paper ned - Add ElderGuardianAppearanceEvent
+        });
+
+        list.forEach((entityplayer) -> {
+            entityplayer.addEffect(new MobEffectInstance(mobeffect), entity, cause); // CraftBukkit
+        });
         return list;
     }
 }
