# StatusEffectUpdate

`com.jsmacrosce.jsmacros.client.api.event.impl.player.EventStatusEffectUpdate`

**Since:** 1.8.4

**Cancellable:** No. Calling `event.cancel()` throws `UnsupportedOperationException`.

Fires while the client processes a status-effect update or removal packet for the local
player. Listeners run before the packet's effect change is applied.  
Updates (including refreshes or downgrades) set [added](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventStatusEffectUpdate_added); removals set [removed](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventStatusEffectUpdate_removed).  
Effects on other entities do not raise this event.  
```js
JsMacros.on("StatusEffectUpdate", JavaWrapper.methodToJava(function (event) {
  if (event.removed) {
    if (event.oldEffect !== null) {
      Chat.log(`Lost ${event.oldEffect.getId()}`);  
    }
    return;  
  }
  if (event.newEffect !== null) {
    const effect = event.newEffect;  
    Chat.log(`${effect.getId()} ${effect.getStrength() + 1} for ${effect.getTime()} ticks`);  
  }
}))
```

## Constructors

### new EventStatusEffectUpdate {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventStatusEffectUpdate_constructor-StatusEffectHelper-StatusEffectHelper-boolean-}

```js
new EventStatusEffectUpdate(StatusEffectHelper oldEffect, StatusEffectHelper newEffect, boolean added)
```

Initializes the event with the supplied effect helpers and update flag; the helpers are
stored as supplied, including `null`, and `removed` is the complement of
`added`.

**Parameters:**
- `oldEffect`: supplied helper for the prior effect, or `null`
- `newEffect`: supplied helper for the incoming effect, or `null`
- `added`: `true` for an update or `false` for a removal; this records the
    event's change type and does not guarantee an effect is present or an update succeeds

## Fields

### added {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventStatusEffectUpdate_added}

```js
added: boolean
```

`true` for an update packet (including a refresh); `false` for a removal.

### newEffect {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventStatusEffectUpdate_newEffect}

```js
newEffect: StatusEffectHelper
```

The effect specified by an update packet, or `null` on a removal. Its strength is
the zero-based amplifier returned by
[StatusEffectHelper.getStrength()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/StatusEffectHelper.md#com.jsmacrosce.jsmacros.client.api.helper.StatusEffectHelper_getStrength-).

### oldEffect {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventStatusEffectUpdate_oldEffect}

```js
oldEffect: StatusEffectHelper
```

A wrapper for the effect stored on the player before the packet is applied, or
`null` if none is stored. On removal, the wrapper is created even if the effect is
absent; in that case [StatusEffectHelper.getRaw()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/core/helpers/BaseHelper.md#com.jsmacrosce.jsmacros.core.helpers.BaseHelper_getRaw-) returns `null`, and effect
accessors cannot be used.

### removed {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventStatusEffectUpdate_removed}

```js
removed: boolean
```

`true` for a removal packet; `false` for an update packet.

## Methods

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventStatusEffectUpdate_toString-}

```js
toString(): String
```

Formats a diagnostic string using the selected effect helper: `newEffect` for an
update and `oldEffect` for a removal. The selected helper's accessors are evaluated
when called; a `null` selected helper or one whose raw effect is `null` causes
a [NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html). The change label is unquoted, so the result is not JSON.

**Returns:** a formatted diagnostic containing the selected effect's ID, strength, duration, and
    added/removed label
