Class PlayerLives

java.lang.Object
com.hypixel.hytale.server.core.modules.entity.component.PlayerLives
All Implemented Interfaces:
Component<EntityStore>, Cloneable

public class PlayerLives extends Object implements Component<EntityStore>
Persists how many lives a player has left.

The component is absent until a feature writes it, so a reader falls back to its own configured count. A count of zero means the player is out of play: PlayerLives.CancelRespawnWhenExhausted refuses to bring them back until something grants them a life.

The component is immutable: every change replaces it, so a component-change system observes each write.

  • Field Details

  • Constructor Details

    • PlayerLives

      public PlayerLives(int remaining)
      Parameters:
      remaining - The number of lives the player has left.
  • Method Details

    • getComponentType

      public static ComponentType<EntityStore, PlayerLives> getComponentType()
      Returns:
      the registered ComponentType of this component.
    • getRemainingOrDefault

      public static int getRemainingOrDefault(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor, int fallback)
      Parameters:
      ref - The entity to read.
      componentAccessor - The accessor to read the component through.
      fallback - The count that applies while nothing wrote the component, usually the configured count a player keeps before a first death.
      Returns:
      the lives the entity has left, or fallback without the component.
    • markExhausted

      public static void markExhausted(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Spends every life the entity has left, adding the component when it is absent. The caller requests the save, because only the owner of the entity knows how it persists.
      Parameters:
      ref - The entity to take out of play.
      componentAccessor - The accessor to write the component through.
    • getRemaining

      public int getRemaining()
      Returns:
      the number of lives the player has left.
    • clone

      @Nonnull public Component<EntityStore> clone()
      Specified by:
      clone in interface Component<EntityStore>
      Returns:
      a clone instance of the original component instance.