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.
  • Constructor Details

  • 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

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