Class PlayerLoader

java.lang.Object
studio.magemonkey.fabled.data.io.PlayerLoader

public class PlayerLoader extends Object
Cache of loaded PlayerAccounts, keyed by player UUID.

The cache is used from the server thread, from async unload tasks and from the auto-save thread. Loading and unloading are compound sequences around file or database I/O, so they are made mutually exclusive per player by lock stripes, while unrelated players still load and save in parallel. A thread never holds more than one stripe: the I/O layer fires Bukkit events, and a listener that asks for another player's data runs without taking a second stripe rather than risking a lock-ordering deadlock.

  • Constructor Details

    • PlayerLoader

      public PlayerLoader()
  • Method Details

    • getPlayerAccounts

      public static PlayerAccounts getPlayerAccounts(org.bukkit.OfflinePlayer player)
      Retrieves the cached accounts for the player, loading them from storage if they are not cached yet.

      Cache hits are lock-free, so the server thread never waits on another thread's save. A miss takes the player's stripe and checks again before loading, so a player is loaded once and never while an unload of the same player is in progress. A hit that lands while an unload is saving can still return the instance that unload is about to evict (#1809).

      Parameters:
      player - player to get the accounts for
      Returns:
      the player's accounts, or null if storage could not produce any
    • loadPlayer

      public static void loadPlayer(org.bukkit.OfflinePlayer player)
      Loads the player's accounts from storage, replacing anything currently cached for them.
      Parameters:
      player - player to load the accounts for
    • unloadPlayer

      public static void unloadPlayer(org.bukkit.OfflinePlayer player)
      Saves the player's accounts and drops them from the cache.

      The built-in backends log and swallow write failures, so the entry is dropped even if the save did not succeed.

      Parameters:
      player - player to unload
    • hasPlayerAccounts

      public static boolean hasPlayerAccounts(org.bukkit.OfflinePlayer player)
      Checks whether accounts are currently cached for the player.
      Parameters:
      player - player to check for
      Returns:
      true if the player's accounts are cached
    • saveAllPlayerAccounts

      public static void saveAllPlayerAccounts()
      Saves every cached player's accounts.
    • saveAllPlayerAccounts

      public static void saveAllPlayerAccounts(boolean clearCache)
      Saves every cached player's accounts, one stripe at a time.

      When clearCache is set, each entry is dropped under the stripe that saved it, so a player who joins during the pass stays cached instead of being discarded unsaved.

      Parameters:
      clearCache - whether to drop each player from the cache once saved
    • getAllPlayerAccounts

      public static Map<UUID,PlayerAccounts> getAllPlayerAccounts()
      Retrieves a snapshot of every cached player's accounts. The map is a copy; the accounts in it are the live instances.
      Returns:
      an unmodifiable snapshot of the cache
    • loadAllPlayerAccounts

      public static void loadAllPlayerAccounts()
      Loads the accounts of every online player.