# NameChange

`com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange`

**Since:** 1.9.1

**Cancellable:** Yes. Call `event.cancel()` in a handler before releasing the event lock.

Fires when an entity's custom-name data changes. Cancelling prevents the update; otherwise,  
listeners can replace [newName](#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_newName), including setting it to `null` to clear the name.

## Constructors

### new EventNameChange {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_constructor-Entity-Component-Component-}

```js
new EventNameChange(Entity entity, Component oldName, Component newName)
```

Wraps the entity and custom-name values for a name-change event; it does not apply the
change or dispatch the event.  
Passing `null` for `entity` causes a `NullPointerException`.

**Parameters:**
- `entity`: non-null entity to wrap
- `oldName`: previous raw custom-name component, or `null` if none was set
- `newName`: supplied raw custom-name component, or `null` to clear the name

## Fields

### entity {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_entity}

```js
entity: EntityHelper<?>
```

Entity whose custom name is changing.

### newName {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_newName}

```js
newName: TextHelper
```

New custom name, or `null` to clear it. A listener may replace the incoming value;  
cancellation prevents the update. Create replacement text with
[Chat.createTextHelperFromString(String)](../../../../../../../../../libraries/com/jsmacrosce/jsmacros/client/api/library/impl/FChat.md#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_createTextHelperFromString-String-).

### oldName {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_oldName}

```js
oldName: TextHelper
```

Previous custom name, or `null` if none was set.

## Methods

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_toString-}

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

Returns a diagnostic string containing the event name and current name values.  
Each value is the corresponding helper's `getString()` result, or the unquoted
token `null`; `newName` therefore reflects its current, potentially
listener-replaced value. This is not JSON serialization.

**Returns:** a string in the form `eventName:{"oldName": oldValue, "newName": newValue}`
