Interface EntitySpawnCallback

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface EntitySpawnCallback
Called when a non-player entity spawns in the world.

This event fires for mobs, NPCs, and other entities, but NOT for players. For player spawning/joining, use PlayerJoinCallback instead.

This event is cancellable. If cancelled, the entity will not spawn.

Example Usage


 EntitySpawnCallback.EVENT.register((entity, location) -> {
   System.out.println("Entity spawned at " + location);
   return EventResult.PASS;
 });

 // Prevent hostile mobs from spawning in a safe zone
 EntitySpawnCallback.EVENT.register(EventPriority.HIGH, (entity, location) -> {
   if (isHostile(entity) && isInSafeZone(location)) {
     return EventResult.CANCEL;
   }
   return EventResult.PASS;
 });
 
  • Field Details

    • EVENT

      static final Event<EntitySpawnCallback> EVENT
      The event instance. Use this to register listeners and fire the event.
  • Method Details

    • onEntitySpawn

      EventResult onEntitySpawn(TaleEntity entity, Location location)
      Called when an entity is about to spawn in the world.
      Parameters:
      entity - the entity that is spawning
      location - the location where the entity will spawn
      Returns:
      the event result - EventResult.CANCEL to prevent the spawn