Class SavedEntityState<T extends org.bukkit.entity.Entity>

java.lang.Object
wbs.utils.util.entities.state.SavedEntityState<T>
All Implemented Interfaces:
org.bukkit.configuration.serialization.ConfigurationSerializable
Direct Known Subclasses:
SavedLivingEntityState

public class SavedEntityState<T extends org.bukkit.entity.Entity> extends Object implements org.bukkit.configuration.serialization.ConfigurationSerializable
Represents a snapshot of an entity, tracking only specific qualities. Can be captured and restored from entities to save an entity's state before returning them to their former state later.
  • Constructor Details

    • SavedEntityState

      public SavedEntityState()
    • SavedEntityState

      public SavedEntityState(Collection<EntityState<? super T>> toTrack)
  • Method Details

    • trackAll

      public void trackAll()
      Add all known states that aren't already being tracked. If using an extending class, such as SavedPlayerState, additional states are tracked for the implementing classes entity type.

      Note that this does not use a concrete way of finding subclasses; the classpath is not scanned, and the generic parameter isn't used. This is manually implemented and will not reflect new changes without updating, including new trackable states created outside of WbsUtils.

    • track

      public SavedEntityState<T> track(Collection<EntityState<? super T>> toTrack)
      Add multiple states to track. Overrides existing states if another state of the same class is already being tracked.
      Parameters:
      toTrack - The new states to track
      Returns:
      The same object (for chaining)
    • track

      public SavedEntityState<T> track(EntityState<? super T> toTrack)
      Add a new state to track.
      Parameters:
      toTrack - The new state to track
      Returns:
      The same object (for chaining)
    • trackIfAbsent

      public SavedEntityState<T> trackIfAbsent(EntityState<? super T> toTrack)
      Add a new state to track, only if another of the same class has not been added.
      Parameters:
      toTrack - The new state to track
      Returns:
      The same object (for chaining)
    • captureState

      public SavedEntityState<T> captureState(T target)
      Capture the tracked states for the given entity.
      Parameters:
      target - The entity to capture states from.
      Returns:
      The same object (for chaining)
    • restoreState

      public SavedEntityState<T> restoreState(T target)
      Restore the captured states to the given entity. The entity provided need not be the same entity the states were originally captured from.
      Parameters:
      target - The entity to restore the states to.
      Returns:
      The same object (for chaining)
    • deserialize

      public static SavedEntityState<?> deserialize(Map<String,Object> args)
    • serialize

      @NotNull public @NotNull Map<String,Object> serialize()
      Specified by:
      serialize in interface org.bukkit.configuration.serialization.ConfigurationSerializable