Class PreCreatureSpawnEvent
java.lang.Object
org.bukkit.event.Event
com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent
- All Implemented Interfaces:
Cancellable
- Direct Known Subclasses:
PhantomPreSpawnEvent
,PreSpawnerSpawnEvent
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
ConstructorDescriptionPreCreatureSpawnEvent
(@NotNull Location location, @NotNull EntityType type, CreatureSpawnEvent.SpawnReason reason) -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull HandlerList
getType()
boolean
Gets the cancellation state of this event.void
setCancelled
(boolean cancel) Cancelling this event is more efficient than cancelling CreatureSpawnEventvoid
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
Methods inherited from class org.bukkit.event.Event
callEvent, getEventName, isAsynchronous
-
Constructor Details
-
PreCreatureSpawnEvent
public PreCreatureSpawnEvent(@NotNull @NotNull Location location, @NotNull @NotNull EntityType type, @NotNull CreatureSpawnEvent.SpawnReason reason)
-
-
Method Details
-
getSpawnLocation
- Returns:
- The location this creature is being spawned at
-
getType
- Returns:
- The type of creature being spawned
-
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
- Specified by:
getHandlers
in classEvent
-
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 interfaceCancellable
- Returns:
- If the spawn of this creature is cancelled or not
-
setCancelled
public void setCancelled(boolean cancel) Cancelling this event is more efficient than cancelling CreatureSpawnEvent- Specified by:
setCancelled
in interfaceCancellable
- Parameters:
cancel
- true if you wish to cancel this event, and abort the spawn of this creature
-