Package io.papermc.paper.event.player

# Class PrePlayerAttackEntityEvent

java.lang.Object
org.bukkit.event.Event
org.bukkit.event.player.PlayerEvent
io.papermc.paper.event.player.PrePlayerAttackEntityEvent

All Implemented Interfaces:
  `Cancellable`

public class PrePlayerAttackEntityEvent extends PlayerEvent implements Cancellable
Called when the player tries to attack an entity. This occurs before any of the damage logic, so cancelling this event will prevent any sort of sounds from being played when attacking. This event will fire as cancelled for certain entities, with `willAttack()` being false to indicate that this entity will not actually be attacked.

Note: there may be other factors (invulnerability, etc) that will prevent this entity from being attacked that this event will not cover

## Nested Class Summary

## Nested classes/interfaces inherited from class org.bukkit.event.Event

`Event.Result`

## Field Summary

### Fields inherited from class org.bukkit.event.player.PlayerEvent

`player`

## Constructor Summary

Constructors
Constructor
Description
`PrePlayerAttackEntityEvent(@NotNull Player who, @NotNull Entity attacked, boolean willAttack)`

## Method Summary

Modifier and Type
Method
Description
`@NotNull Entity`
`getAttacked()`
Gets the entity that was attacked in this event.
`static @NotNull HandlerList`
`getHandlerList()`
`@NotNull HandlerList`
`getHandlers()`
`boolean`
`isCancelled()`
Gets the cancellation state of this event.
`void`
`setCancelled(boolean cancel)`
Sets if this attack should be cancelled, note if `willAttack()` returns false this event will always be cancelled.
`boolean`
`willAttack()`
Gets if this entity will be attacked normally.

### Methods inherited from class org.bukkit.event.player.PlayerEvent

`getPlayer`

### Methods inherited from class org.bukkit.event.Event

`callEvent, getEventName, isAsynchronous`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### PrePlayerAttackEntityEvent

public PrePlayerAttackEntityEvent(@NotNull @NotNull Player who, @NotNull @NotNull Entity attacked, boolean willAttack)

## Method Details

### getAttacked

@NotNull public @NotNull Entity getAttacked()
Gets the entity that was attacked in this event.

Returns:
  entity that was attacked

### willAttack

public boolean willAttack()
Gets if this entity will be attacked normally. Entities like falling sand will return false because their entity type does not allow them to be attacked.

Note: there may be other factors (invulnerability, etc) that will prevent this entity from being attacked that this event will not cover

Returns:
  if the entity will actually be attacked

### getHandlers

@NotNull public @NotNull HandlerList getHandlers()

Specified by:
  `getHandlers` in class `Event`

### getHandlerList

@NotNull public static @NotNull HandlerList getHandlerList()

### isCancelled

public boolean isCancelled()
Description copied from interface: `Cancellable`
Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins

Specified by:
  `isCancelled` in interface `Cancellable`
Returns:
  true if this event is cancelled

### setCancelled

public void setCancelled(boolean cancel)
Sets if this attack should be cancelled, note if `willAttack()` returns false this event will always be cancelled.

Specified by:
  `setCancelled` in interface `Cancellable`
Parameters:
  `cancel` - true if you wish to cancel this event