Package valorless.valorlessutils.cache
Class PlayerCache
java.lang.Object
valorless.valorlessutils.cache.PlayerCache
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdds a player to the cache with the given username andUUID.getCache()Returns a shallow copy of the player cache.static org.bukkit.OfflinePlayerRetrieves theOfflinePlayerassociated with the given username from the cache.static UUIDRetrieves theUUIDassociated with the given username from the cache.static voidinit()Initializes the PlayerCache by registering the listener and asynchronously populating the cache with all known offline players.
-
Constructor Details
-
PlayerCache
public PlayerCache()
-
-
Method Details
-
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
Retrieves theUUIDassociated with the given username from the cache.- Parameters:
username- the player's username to look up- Returns:
- the
UUIDof the player, ornullif not found in the cache
-
getPlayer
Retrieves theOfflinePlayerassociated with the given username from the cache.- Parameters:
username- the player's username to look up- Returns:
- the
OfflinePlayerinstance, ornullif not found in the cache
-
getCache
Returns a shallow copy of the player cache. -
addPlayer
Adds a player to the cache with the given username andUUID.- Parameters:
username- the player's usernameuuid- the player'sUUID
-