Class UsernameCache

java.lang.Object
net.neoforged.neoforge.common.UsernameCache

public final class UsernameCache extends Object
Caches player's last known usernames

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.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
    Used for saving the Gson representation of the cache to disk
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final com.google.gson.Gson
     
    private static final org.apache.logging.log4j.Logger
     
    private static Map<UUID,String>
     
    private static final Path
     
    private static final org.apache.logging.log4j.Marker
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Check if the cache contains the given player's username
    static @Nullable String
    Get the player's last known username
    static Map<UUID,String>
    Get an immutable copy of the cache's underlying map
    protected static void
    Load the cache from file
    protected static boolean
    Remove a player's username from the cache
    protected static void
    Save the cache to file
    protected static void
    setUsername(UUID uuid, String username)
    Set a player's current usernamee

    Methods inherited from class java.lang.Object

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

    • map

      private static Map<UUID,String> map
    • saveFile

      private static final Path saveFile
    • gson

      private static final com.google.gson.Gson gson
    • LOGGER

      private static final org.apache.logging.log4j.Logger LOGGER
    • USRCACHE

      private static final org.apache.logging.log4j.Marker USRCACHE
  • Constructor Details

    • UsernameCache

      private UsernameCache()
  • Method Details

    • setUsername

      protected static void setUsername(UUID uuid, String username)
      Set a player's current usernamee
      Parameters:
      uuid - the player's UUID
      username - the player's username
    • removeUsername

      protected static boolean removeUsername(UUID uuid)
      Remove a player's username from the cache
      Parameters:
      uuid - the player's UUID
      Returns:
      if the cache contained the user
    • getLastKnownUsername

      @Nullable public static @Nullable String getLastKnownUsername(UUID uuid)
      Get the player's last known username

      May be null

      Parameters:
      uuid - the player's UUID
      Returns:
      the player's last known username, or null if the cache doesn't have a record of the last username
    • containsUUID

      public static boolean containsUUID(UUID uuid)
      Check if the cache contains the given player's username
      Parameters:
      uuid - the player's UUID
      Returns:
      if the cache contains a username for the given player
    • getMap

      public static Map<UUID,String> getMap()
      Get an immutable copy of the cache's underlying map
      Returns:
      the map
    • save

      protected static void save()
      Save the cache to file
    • load

      protected static void load()
      Load the cache from file