Interface ScenarioStore


public interface ScenarioStore
A scenario's scratch space for one match.

Everything stored here is private to a single scenario in a single game and is discarded when that match ends, which is what lets the same scenario run in several matches at once without any of them seeing each other's state.

The store is thread-safe.

Since:
1.6.0
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes everything.
    void
    clearPlayer(@NotNull UUID playerId)
    Drops everything stored against one participant.
    <T> T
    computeIfAbsent(@NotNull String key, @NotNull Class<T> type, @NotNull Supplier<T> factory)
    The stored value, creating and storing one through factory when absent.
    boolean
    contains(@NotNull String key)
     
    <T> @NotNull Optional<T>
    get(@NotNull String key, @NotNull Class<T> type)
    The stored value, empty when absent or of a different type.
    <T> T
    getOrDefault(@NotNull String key, @NotNull Class<T> type, T fallback)
    The stored value, or fallback when absent or of a different type.
    <T> @NotNull Optional<T>
    getPlayer(@NotNull UUID playerId, @NotNull String key, @NotNull Class<T> type)
    Reads a value stored against one participant.
    @NotNull Set<String>
     
    boolean
    remove(@NotNull String key)
    Removes a key and reports whether anything was stored under it.
    void
    set(@NotNull String key, @Nullable Object value)
    Stores a value; a null value removes the key.
    void
    setPlayer(@NotNull UUID playerId, @NotNull String key, @Nullable Object value)
    Stores a value against one participant; a null value removes it.
  • Method Details

    • get

      @NotNull <T> @NotNull Optional<T> get(@NotNull @NotNull String key, @NotNull @NotNull Class<T> type)
      The stored value, empty when absent or of a different type.
    • getOrDefault

      <T> T getOrDefault(@NotNull @NotNull String key, @NotNull @NotNull Class<T> type, T fallback)
      The stored value, or fallback when absent or of a different type.
    • computeIfAbsent

      @NotNull <T> T computeIfAbsent(@NotNull @NotNull String key, @NotNull @NotNull Class<T> type, @NotNull @NotNull Supplier<T> factory)
      The stored value, creating and storing one through factory when absent.
    • set

      void set(@NotNull @NotNull String key, @Nullable @Nullable Object value)
      Stores a value; a null value removes the key.
    • remove

      boolean remove(@NotNull @NotNull String key)
      Removes a key and reports whether anything was stored under it.
    • contains

      boolean contains(@NotNull @NotNull String key)
    • keys

      @NotNull @NotNull Set<String> keys()
    • clear

      void clear()
      Removes everything. Cleanup does this automatically.
    • getPlayer

      @NotNull <T> @NotNull Optional<T> getPlayer(@NotNull @NotNull UUID playerId, @NotNull @NotNull String key, @NotNull @NotNull Class<T> type)
      Reads a value stored against one participant.
    • setPlayer

      void setPlayer(@NotNull @NotNull UUID playerId, @NotNull @NotNull String key, @Nullable @Nullable Object value)
      Stores a value against one participant; a null value removes it.
    • clearPlayer

      void clearPlayer(@NotNull @NotNull UUID playerId)
      Drops everything stored against one participant.

      Useful when a player leaves mid-match; the store does not do this on its own, because a scenario may want a disconnecting player's state to survive a reconnect.