# 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, a
 joined listener can replace the name with `setNewName(...)`, including setting it
 to `null` to clear it.

## 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-).

**Deprecated:** Removal in 3.0.0: Use [getNewName()](#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_getNewName-) and [setNewName(TextHelper)](#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_setNewName-TextHelper-) instead.

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

```js
oldName: TextHelper
```

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

## Methods

### getNewName {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_getNewName-}

```js
getNewName(): TextHelper
```

Returns the incoming custom name, or `null` when the name is being cleared.

**Returns:** the current replacement helper, or `null`

**Since:** 2.2.0

### setNewName {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventNameChange_setNewName-TextHelper-}

```js
setNewName(TextHelper newName): void
```

Replaces the incoming custom name. `null` clears the name. 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-).

**Parameters:**
- `newName`: replacement helper, or `null` to clear the name

**Since:** 2.2.0

### 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}`
