Package com.destroystokyo.paper.event.entity

# Class PreCreatureSpawnEvent

java.lang.Object
org.bukkit.event.Event
com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent

All Implemented Interfaces:
  `Cancellable`

Direct Known Subclasses:
  `PhantomPreSpawnEvent`, `PreSpawnerSpawnEvent`

public class PreCreatureSpawnEvent extends Event implements Cancellable
WARNING: This event only fires for a limited number of cases, and not for every case that CreatureSpawnEvent does. You should still listen to CreatureSpawnEvent as a backup, and only use this event as an "enhancement". The intent of this event is to improve server performance, so it fires even if the spawning might fail later, for example when the entity would be unable to spawn due to limited space or lighting. Currently: NATURAL and SPAWNER based reasons. Please submit a Pull Request for future additions. Also, Plugins that replace Entity Registrations with their own custom entities might not fire this event.

## Nested Class Summary

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

`Event.Result`

## Constructor Summary

Constructors
Constructor
Description
`PreCreatureSpawnEvent(@NotNull Location location, @NotNull EntityType type, CreatureSpawnEvent.SpawnReason reason)`

## Method Summary

Modifier and Type
Method
Description
`static @NotNull HandlerList`
`getHandlerList()`
`@NotNull HandlerList`
`getHandlers()`
`CreatureSpawnEvent.SpawnReason`
`getReason()`
`@NotNull Location`
`getSpawnLocation()`
`@NotNull EntityType`
`getType()`
`boolean`
`isCancelled()`
Gets the cancellation state of this event.
`void`
`setCancelled(boolean cancel)`
Cancelling this event is more effecient than cancelling CreatureSpawnEvent
`void`
`setShouldAbortSpawn(boolean shouldAbortSpawn)`
Set this if you are more blanket blocking all types of these spawns, and wish to abort the spawn process from trying more attempts after this cancellation.
`boolean`
`shouldAbortSpawn()`

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

### PreCreatureSpawnEvent

public PreCreatureSpawnEvent(@NotNull @NotNull Location location, @NotNull @NotNull EntityType type, @NotNull CreatureSpawnEvent.SpawnReason reason)

## Method Details

### getSpawnLocation

@NotNull public @NotNull Location getSpawnLocation()

Returns:
  The location this creature is being spawned at

### getType

@NotNull public @NotNull EntityType getType()

Returns:
  The type of creature being spawned

### getReason

@NotNull public CreatureSpawnEvent.SpawnReason getReason()

Returns:
  Reason this creature is spawning (ie, NATURAL vs SPAWNER)

### shouldAbortSpawn

public boolean shouldAbortSpawn()

Returns:
  If the spawn process should be aborted vs trying more attempts

### setShouldAbortSpawn

public void setShouldAbortSpawn(boolean shouldAbortSpawn)
Set this if you are more blanket blocking all types of these spawns, and wish to abort the spawn process from trying more attempts after this cancellation.

Parameters:
  `shouldAbortSpawn` - Set if the spawn process should be aborted vs trying more attempts

### 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:
  If the spawn of this creature is cancelled or not

### setCancelled

public void setCancelled(boolean cancel)
Cancelling this event is more effecient than cancelling CreatureSpawnEvent

Specified by:
  `setCancelled` in interface `Cancellable`
Parameters:
  `cancel` - true if you wish to cancel this event, and abort the spawn of this creature