Class SavedEntity

java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.SavedEntity

public class SavedEntity extends Object
Represents a serialized snapshot of an entity, including its type and associated data.

This abstraction supports both vanilla EntityType instances and CustomEntity definitions, allowing entities to be captured, stored, and later reconstructed in different contexts.

All data is stored in a format-agnostic representation using DynamicOps.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     <D> 
    SavedEntity(Either<org.bukkit.entity.EntityType, CustomEntity<? extends org.bukkit.entity.LivingEntity>> type, D rawData, DynamicOps<D> ops)
    Constructs a new saved entity instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyData(org.bukkit.entity.Entity entity)
    Applies serialized data onto a target entity.
    static <D> SavedEntity
    create(org.bukkit.entity.Entity entity, DynamicOps<D> ops)
    Creates a SavedEntity from a live Bukkit Entity.
    Retrieves the raw serialized data.
    Either<org.bukkit.entity.EntityType, CustomEntity<? extends org.bukkit.entity.LivingEntity>>
    Retrieves the entity type representation.
    org.bukkit.entity.Entity
    spawn(WorldGenAccess level, org.bukkit.Location loc)
    Spawns this entity in a WorldGenAccess context.
    void
    spawn(org.bukkit.entity.Entity entity)
    Applies this saved entity onto an existing entity instance.
    void
    spawn(org.bukkit.entity.Entity entity, CustomEntitySpawnEvent.SpawnReason reason)
    Applies this saved entity onto an existing entity instance.
    org.bukkit.entity.Entity
    spawn(org.bukkit.Location loc)
    Spawns this entity at a location using plugin spawn reason.
    org.bukkit.entity.Entity
    spawn(org.bukkit.Location loc, CustomEntitySpawnEvent.SpawnReason reason)
    Spawns this entity at a location.
    void
    spawnFromInstance(org.bukkit.entity.Entity nativeEntity)
    Applies this saved entity onto a pre-existing native instance.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SavedEntity

      public <D> SavedEntity(Either<org.bukkit.entity.EntityType, CustomEntity<? extends org.bukkit.entity.LivingEntity>> type, D rawData, DynamicOps<D> ops)
      Constructs a new saved entity instance.
      Type Parameters:
      D - the encoded data type
      Parameters:
      type - the entity type representation
      rawData - the serialized data payload
      ops - the dynamic operations instance
  • Method Details

    • create

      public static <D> SavedEntity create(org.bukkit.entity.Entity entity, DynamicOps<D> ops)
      Creates a SavedEntity from a live Bukkit Entity.

      If the entity is associated with a CustomEntity, its identifier is stored. Otherwise, the vanilla entity type is recorded.

      Type Parameters:
      D - the encoded data type
      Parameters:
      entity - the source entity
      ops - the dynamic operations instance
      Returns:
      a new saved entity instance
    • getType

      public Either<org.bukkit.entity.EntityType, CustomEntity<? extends org.bukkit.entity.LivingEntity>> getType()
      Retrieves the entity type representation.
      Returns:
      the Either containing either a vanilla type or custom entity
    • getRawData

      public Object getRawData()
      Retrieves the raw serialized data.
      Returns:
      the raw data object
    • spawn

      public org.bukkit.entity.Entity spawn(org.bukkit.Location loc)
      Spawns this entity at a location using plugin spawn reason.
      Parameters:
      loc - the spawn location
      Returns:
      the spawned entity
    • spawn

      public org.bukkit.entity.Entity spawn(org.bukkit.Location loc, CustomEntitySpawnEvent.SpawnReason reason)
      Spawns this entity at a location.
      Parameters:
      loc - the spawn location
      reason - the spawn reason
      Returns:
      the spawned entity
    • spawn

      public org.bukkit.entity.Entity spawn(WorldGenAccess level, org.bukkit.Location loc)
      Spawns this entity in a WorldGenAccess context.
      Parameters:
      level - the world generation access
      loc - the spawn location
      Returns:
      the spawned entity
    • spawn

      public void spawn(org.bukkit.entity.Entity entity)
      Applies this saved entity onto an existing entity instance.
      Parameters:
      entity - the target entity
    • spawn

      public void spawn(org.bukkit.entity.Entity entity, CustomEntitySpawnEvent.SpawnReason reason)
      Applies this saved entity onto an existing entity instance.
      Parameters:
      entity - the target entity
      reason - the spawn reason
    • spawnFromInstance

      public void spawnFromInstance(org.bukkit.entity.Entity nativeEntity)
      Applies this saved entity onto a pre-existing native instance.
      Parameters:
      nativeEntity - the entity instance
    • applyData

      public void applyData(org.bukkit.entity.Entity entity)
      Applies serialized data onto a target entity.
      Parameters:
      entity - the target entity