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 Details

    • SavedEntity

      public <D> SavedEntity(Either<org.bukkit.entity.EntityType, CustomEntity> 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> 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