Class PlayerCache

java.lang.Object
valorless.valorlessutils.cache.PlayerCache
All Implemented Interfaces:
org.bukkit.event.Listener

public class PlayerCache extends Object implements org.bukkit.event.Listener
A cache that maps player usernames to their UUIDs.

The cache is populated asynchronously on initialization with all known offline players, and is kept up-to-date as players join the server.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addPlayer(String username, UUID uuid)
    Adds a player to the cache with the given username and UUID.
    Returns a shallow copy of the player cache.
    static org.bukkit.OfflinePlayer
    getPlayer(String username)
    Retrieves the OfflinePlayer associated with the given username from the cache.
    static UUID
    getUUID(String username)
    Retrieves the UUID associated with the given username from the cache.
    static void
    Initializes the PlayerCache by registering the listener and asynchronously populating the cache with all known offline players.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PlayerCache

      public PlayerCache()
  • Method Details

    • init

      @Internal @DoNotCall public static void init()
      Initializes the PlayerCache by registering the listener and asynchronously populating the cache with all known offline players.

      This method is for internal use only and should not be called manually.

    • getUUID

      public static UUID getUUID(String username)
      Retrieves the UUID associated with the given username from the cache.
      Parameters:
      username - the player's username to look up
      Returns:
      the UUID of the player, or null if not found in the cache
    • getPlayer

      public static org.bukkit.OfflinePlayer getPlayer(String username)
      Retrieves the OfflinePlayer associated with the given username from the cache.
      Parameters:
      username - the player's username to look up
      Returns:
      the OfflinePlayer instance, or null if not found in the cache
    • getCache

      public static HashMap<String,UUID> getCache()
      Returns a shallow copy of the player cache.
      Returns:
      a HashMap copy mapping usernames to their UUIDs
    • addPlayer

      public static void addPlayer(String username, UUID uuid)
      Adds a player to the cache with the given username and UUID.
      Parameters:
      username - the player's username
      uuid - the player's UUID