Class SessionSpawnEntityEvent

java.lang.Object
org.geysermc.geyser.api.event.connection.ConnectionEvent
org.geysermc.geyser.api.event.bedrock.SessionSpawnEntityEvent
All Implemented Interfaces:
org.geysermc.event.Cancellable, org.geysermc.event.Event
Direct Known Subclasses:
ServerAttachParrotsEvent, ServerSpawnEntityEvent

public abstract class SessionSpawnEntityEvent extends ConnectionEvent implements org.geysermc.event.Cancellable
Base event for entity spawning visible to a specific Bedrock connection. Specific subtypes are ServerSpawnEntityEvent (non-player entities) and ServerAttachParrotsEvent (shoulder parrots).

The event is cancellable; cancelling it suppresses spawning the entity on the Bedrock client. Setting the definition to null has the same effect.

Since:
2.11.0
  • Constructor Details

    • SessionSpawnEntityEvent

      @Internal public SessionSpawnEntityEvent(GeyserConnection connection)
  • Method Details

    • definition

      public abstract @Nullable GeyserEntityDefinition definition()
      Returns the Bedrock entity definition that will be sent to the Bedrock client.
      Returns:
      the entity definition, or null if none is currently set
      Since:
      2.11.0
    • definition

      public abstract void definition(@Nullable GeyserEntityDefinition definition)
      Overrides the Bedrock entity definition when spawning this entity on the Bedrock client.

      The supplied definition must have been previously registered in the GeyserDefineEntitiesEvent; passing an unregistered definition will throw IllegalStateException. Passing null cancels the spawn for this connection.

      Parameters:
      definition - the replacement entity definition, or null to suppress the spawn
      Throws:
      IllegalStateException - if the provided definition has not been registered
      Since:
      2.11.0
    • preSpawnConsumer

      public abstract void preSpawnConsumer(Consumer<GeyserEntity> consumer)
      Registers a callback that is invoked with the GeyserEntity instance just before the entity is spawned. This means that EntityData.byJavaId(int), EntityData.byUuid(java.util.UUID), and related lookups will not find the entity from within the consumer.

      Use this callback to apply initial overrides such as entity data values (scale, width, height, hitboxes) or entity properties before the spawn packet is sent to the client. If multiple consumers are registered, they run in the order they were added.

      The consumer is not called if the event is cancelled.

      Parameters:
      consumer - the callback receiving the freshly created entity
      Since:
      2.11.0