Interface EntityState<T extends org.bukkit.entity.Entity>

Type Parameters:
T - The Entity subclass this state may be used on
All Known Implementing Classes:
AllowFlightState, FallDistanceState, FireTicksState, FlyingState, GameModeState, HealthState, HungerState, InventoryState, InvulnerableState, LocationState, PotionEffectsState, RemainingAirState, SaturationState, ScoreboardState, VelocityState, XPState

public interface EntityState<T extends org.bukkit.entity.Entity>
Represents a capture of some property of an entity, such as health.

The data captured in EntityStates should be immutable to the game loop; that is, after capturing, it shouldn't matter what happens to the captured entity. When an entity is restored, the tracked state should be identical to the moment it was captured, unless the EntityState object was directly interacted with.

As an example, a captured ItemStack should appear the same after being restored as it did when captured, even if the original ItemStack had it's amount or ItemMeta changed.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    captureState(T target)
    Capture the state of an instance of EntityState according to the implementation, and store it until restoreState(T) is called.
    @NotNull Set<Class<? extends EntityState<?>>>
    Used to build a graph of captured states, allowing states to be restored in the appropriate order, such as restoring AllowFlightState after GameModeState, to prevent a change to GameMode.SURVIVAL from overriding the Player.getAllowFlight() state.
    void
    restoreState(T target)
    Restore the state of an instance of EntityState according to the implementation.
  • Method Details

    • captureState

      void captureState(T target)
      Capture the state of an instance of EntityState according to the implementation, and store it until restoreState(T) is called.
      Parameters:
      target - The EntityState from which to capture.
    • restoreState

      void restoreState(T target)
      Restore the state of an instance of EntityState according to the implementation.
      Parameters:
      target - The EntityState for which to the stored state.
    • restoreAfter

      @NotNull @NotNull Set<Class<? extends EntityState<?>>> restoreAfter()
      Used to build a graph of captured states, allowing states to be restored in the appropriate order, such as restoring AllowFlightState after GameModeState, to prevent a change to GameMode.SURVIVAL from overriding the Player.getAllowFlight() state.
      Returns:
      A set of classes to restore after, if present in a given SavedEntityState.