# AttackEntity

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

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

Fires after the local player's entity-attack action.  
 ```js
JsMacros.on("AttackEntity", JavaWrapper.methodToJava(function (event) {
  if (event.entity instanceof EntityHelpers.Player) {
    Chat.log(`Attacked player ${event.entity.getName().getString()}`);  
  }
}))
 ```

## Constructors

### new EventAttackEntity {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventAttackEntity_constructor-Entity-}

```js
new EventAttackEntity(Entity entity)
```

Initializes the event with the client core and wraps the supplied entity.  
 The helper refers to the supplied entity; it is not a copy or snapshot.  
 A `null` entity causes [NullPointerException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/NullPointerException.html) during wrapping.

**Parameters:**
- `entity`: the Minecraft entity to wrap

## Fields

### entity {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventAttackEntity_entity}

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

The attacked entity, wrapped in the most specific
 [EntityHelper](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/entity/EntityHelper.md) subclass for its
 type. Use `instanceof EntityHelpers.Player` and the other namespace types to narrow
 the wrapper; the `as...()` helpers are casts. Its type and name are available from
 [getType()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/entity/EntityHelper.md#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getType-)
 and [getName()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/entity/EntityHelper.md#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getName-).

## Methods

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

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

Returns a diagnostic string containing the event name and stored entity helper.  
 The helper's representation is determined by its runtime implementation; the
 result uses the literal format `%s:{"entity": %s}` and is not JSON as a whole.

**Returns:** the formatted event name and entity-helper representation
