Klasse ProgressionService

java.lang.Object
de.delinkedde.mobarenareborn.progression.ProgressionService

public final class ProgressionService extends Object
Tracks per-player, per-class experience and levels and persists them.

Progress is loaded into an in-memory cache when a player joins, mutated as they earn experience, and saved on level-up and when they leave. The level-up threshold comes from the leveling.curve expression, evaluated with the level variable.

Database access is serialised onto a single background thread so the SQLite connection is never used concurrently and never blocks the main server thread during a wave. Writes (level-up and leave flushes) are submitted asynchronously; the join-time load is run on the same executor and awaited, which keeps the cache ready before the round and guarantees ordered access. The shared executor is drained by the service container on shutdown, before the database closes.

  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
    ProgressionService(@NotNull MobArenaPlugin plugin, @NotNull ConfigManager config, @NotNull ClassLevelDao dao, @NotNull DbExecutor dbExecutor)
     
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    void
    awardXp(@NotNull Player player, @NotNull String className, int maxLevel, long amount)
    Awards experience to a player's class, applying any level-ups and persisting on change.
    void
    flush(@NotNull UUID uuid)
    Persists all cached progress for a player.
    void
    Persists all cached progress for every player.
    void
    load(@NotNull UUID uuid)
    Loads a player's stored progress into the cache.
    @NotNull ClassProgress
    progress(@NotNull UUID uuid, @NotNull String className)
    Returns the player's progress for a class, creating a fresh level-one entry if absent.
    void
    unload(@NotNull UUID uuid)
    Drops a player's cached progress after a final flush.
    long
    xpForNextLevel(int level)
    Returns the experience required to advance from the given level to the next.

    Von Klasse geerbte Methoden java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Konstruktordetails

    • ProgressionService

      public ProgressionService(@NotNull @NotNull MobArenaPlugin plugin, @NotNull @NotNull ConfigManager config, @NotNull @NotNull ClassLevelDao dao, @NotNull @NotNull DbExecutor dbExecutor)
      Parameter:
      plugin - the owning plugin, used for logging
      config - the configuration manager providing the level curve
      dao - the data access object for class levels
      dbExecutor - the shared database thread
  • Methodendetails

    • load

      public void load(@NotNull @NotNull UUID uuid)
      Loads a player's stored progress into the cache.
      Parameter:
      uuid - the player's unique id
    • progress

      @NotNull public @NotNull ClassProgress progress(@NotNull @NotNull UUID uuid, @NotNull @NotNull String className)
      Returns the player's progress for a class, creating a fresh level-one entry if absent.
      Parameter:
      uuid - the player's unique id
      className - the class identifier
      Gibt zurück:
      the progress
    • xpForNextLevel

      public long xpForNextLevel(int level)
      Returns the experience required to advance from the given level to the next.
      Parameter:
      level - the current level
      Gibt zurück:
      the threshold, at least one
    • awardXp

      public void awardXp(@NotNull @NotNull Player player, @NotNull @NotNull String className, int maxLevel, long amount)
      Awards experience to a player's class, applying any level-ups and persisting on change.
      Parameter:
      player - the player
      className - the class identifier
      maxLevel - the class level cap
      amount - the experience to award
    • flush

      public void flush(@NotNull @NotNull UUID uuid)
      Persists all cached progress for a player.
      Parameter:
      uuid - the player's unique id
    • flushAll

      public void flushAll()
      Persists all cached progress for every player. Used by the periodic autosave and on plugin shutdown (before the background executor is drained) so banked experience is never lost when players are still online.
    • unload

      public void unload(@NotNull @NotNull UUID uuid)
      Drops a player's cached progress after a final flush.
      Parameter:
      uuid - the player's unique id