Class PreCreatureSpawnEvent

All Implemented Interfaces:
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()
      The location this creature is being spawned at
    • getType

      @NotNull public @NotNull EntityType getType()
      The type of creature being spawned
    • getReason

      Reason this creature is spawning (ie, NATURAL vs SPAWNER)
    • shouldAbortSpawn

      public boolean shouldAbortSpawn()
      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.
      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
      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
      cancel - true if you wish to cancel this event, and abort the spawn of this creature