public final class UsernameCache
extends java.lang.Object
Modders should use getLastKnownUsername(UUID)
to determine a players
last known username.
For convenience, getMap()
is provided to get an immutable copy of
the caches underlying map.
Modifier and Type | Class and Description |
---|---|
private static class |
UsernameCache.SaveThread
Used for saving the
Gson
representation of the cache to disk |
Modifier and Type | Field and Description |
---|---|
private static com.google.gson.Gson |
gson |
private static org.apache.logging.log4j.Logger |
LOGGER |
private static java.util.Map<java.util.UUID,java.lang.String> |
map |
private static java.nio.file.Path |
saveFile |
private static org.apache.logging.log4j.Marker |
USRCACHE |
Modifier | Constructor and Description |
---|---|
private |
UsernameCache() |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsUUID(java.util.UUID uuid)
Check if the cache contains the given player's username
|
static java.lang.String |
getLastKnownUsername(java.util.UUID uuid)
Get the player's last known username
|
static java.util.Map<java.util.UUID,java.lang.String> |
getMap()
Get an immutable copy of the cache's underlying map
|
protected static void |
load()
Load the cache from file
|
protected static boolean |
removeUsername(java.util.UUID uuid)
Remove a player's username from the cache
|
protected static void |
save()
Save the cache to file
|
protected static void |
setUsername(java.util.UUID uuid,
java.lang.String username)
Set a player's current usernamee
|
private static java.util.Map<java.util.UUID,java.lang.String> map
private static final java.nio.file.Path saveFile
private static final com.google.gson.Gson gson
private static final org.apache.logging.log4j.Logger LOGGER
private static final org.apache.logging.log4j.Marker USRCACHE
protected static void setUsername(java.util.UUID uuid, java.lang.String username)
uuid
- the player's UUID
username
- the player's usernameprotected static boolean removeUsername(java.util.UUID uuid)
uuid
- the player's UUID
@Nullable public static java.lang.String getLastKnownUsername(java.util.UUID uuid)
May be null
uuid
- the player's UUID
null
if the
cache doesn't have a record of the last usernamepublic static boolean containsUUID(java.util.UUID uuid)
uuid
- the player's UUID
public static java.util.Map<java.util.UUID,java.lang.String> getMap()
protected static void save()
protected static void load()