Skip to content

Continuous Effects

Gugas749 edited this page Nov 5, 2026 · 1 revision

Continuous effects

AbyssEffectHandler keeps effects on an entity for as long as you want, refreshing them before they run out. That avoids the night-vision flicker and "effect ends for one tick" problems.

import com.gugas749.abysscore.api.effects.AbyssEffectHandler;

// Start (server side): keep Night Vision on while wearing the helmet
AbyssEffectHandler.registerContinuousEffect(player.getUUID(),
        new MobEffectInstance(MobEffects.NIGHT_VISION, 400, 0, false, false));   // ambient=false, particles=false

// Several at once
AbyssEffectHandler.registerContinuousEffect(player.getUUID(), List.of(
        new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 400, 0, false, false),
        new MobEffectInstance(MobEffects.WATER_BREATHING, 400, 0, false, false)));

// Stop one (matched by effect TYPE, so any instance of Night Vision works)
AbyssEffectHandler.unregisterContinuousEffect(player.getUUID(),
        new MobEffectInstance(MobEffects.NIGHT_VISION, 400, 0));

// Stop all of them for this entity
AbyssEffectHandler.unregisterEveryContinuousEffect(player.getUUID());

// Change the level: registering the same effect TYPE again replaces the old instance
AbyssEffectHandler.registerContinuousEffect(player.getUUID(),
        new MobEffectInstance(MobEffects.DAMAGE_BOOST, 400, 1, false, false));   // Strength II replaces Strength I

// Queries
AbyssEffectHandler.hasContinuousEffect(player.getUUID(), new MobEffectInstance(MobEffects.NIGHT_VISION, 1));
List<MobEffectInstance> active = AbyssEffectHandler.getContinuousEffects(player.getUUID());   // read-only copy

How it works: on every server-side living-entity tick, a registered effect is re-applied from your instance if it's missing, or if it has fewer than 200 ticks left (or half its duration for effects shorter than 400 ticks). Effects with infinite duration are applied once and left alone.

Tips:

  • Use a duration of 400 or more for Night Vision. The screen starts flickering below 200 ticks, and with 400 the refresh happens at 200.
  • Unregistering doesn't remove the effect. It only stops refreshing it, so the effect runs out on its own. To remove it right away, also call entity.removeEffect(MobEffects.NIGHT_VISION).
  • Cleanup is automatic. Players are forgotten on logout. Other entities are forgotten when they die or are removed for good (killed, despawned, /kill). Entities in unloaded chunks keep their entry, because they come back with the same UUID.
  • Players keep their continuous effects through death and respawn (same UUID).
  • Works with any LivingEntity, keyed by UUID.
  • Not saved: register again after a server restart, e.g. on login or when the condition is checked.
Method Description
registerContinuousEffect(UUID, MobEffectInstance) Keep it on. The same type registered again replaces the old one.
registerContinuousEffect(UUID, List<MobEffectInstance>) Several at once
unregisterContinuousEffect(UUID, MobEffectInstance) Stop refreshing that effect type
unregisterEveryContinuousEffect(UUID) Stop refreshing all of them
hasContinuousEffect(UUID, MobEffectInstance) Is that type registered?
getContinuousEffects(UUID) Read-only copy of the registered instances
onEntityTick, onPlayerLeave, onEntityLeaveLevel Internal: called by AbyssCore's loader listeners

Example — an item that gives effects while held:

// in a server player tick handler
boolean holding = player.getMainHandItem().is(MyItems.LANTERN.get());
boolean had = LANTERN_USERS.contains(player.getUUID());
if (holding && !had) {
    LANTERN_USERS.add(player.getUUID());
    AbyssEffectHandler.registerContinuousEffect(player.getUUID(),
            new MobEffectInstance(MobEffects.NIGHT_VISION, 400, 0, false, false));
} else if (!holding && had) {
    LANTERN_USERS.remove(player.getUUID());
    AbyssEffectHandler.unregisterContinuousEffect(player.getUUID(), new MobEffectInstance(MobEffects.NIGHT_VISION, 1));
    player.removeEffect(MobEffects.NIGHT_VISION);
}

Clone this wiki locally