Class SkinCache

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

public class SkinCache extends Object implements org.bukkit.event.Listener
A cache that maps player usernames to their PlayerProfiles, including skin data.

The cache is loaded from disk on initialization, populated with currently online players, and persisted back to disk on shutdown. It is kept up-to-date as players join the server.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static HashMap<String,org.bukkit.profile.PlayerProfile>
    Returns a shallow copy of the skin cache.
    static org.bukkit.profile.PlayerProfile
    getProfile(String username)
    Gets the PlayerProfile for the given player username.
    static URL
    getSkin(String username)
    Gets the skin URL for the given player username.
    static void
    Initializes the SkinCache by registering the event listener, loading the cache from disk, and adding all currently online players to the cache.
    static boolean
    Removes a player's PlayerProfile from the cache.
    static void
    Saves the skin cache to the skins.yml file and logs the result.

    Methods inherited from class java.lang.Object

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

    • SkinCache

      public SkinCache()
  • Method Details

    • getCache

      public static HashMap<String,org.bukkit.profile.PlayerProfile> getCache()
      Returns a shallow copy of the skin cache.
      Returns:
      a HashMap copy mapping player usernames to their PlayerProfiles
    • init

      @Internal @DoNotCall public static void init()
      Initializes the SkinCache by registering the event listener, loading the cache from disk, and adding all currently online players to the cache.

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

    • shutdown

      @Internal @DoNotCall public static void shutdown()
      Saves the skin cache to the skins.yml file and logs the result.

      If the cache file or its parent directory does not exist, they will be created. This method is called when the plugin is disabled.

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

    • getProfile

      public static org.bukkit.profile.PlayerProfile getProfile(String username)
      Gets the PlayerProfile for the given player username.
      Parameters:
      username - the name of the player whose profile is to be retrieved
      Returns:
      the PlayerProfile of the specified player, or null if not found in the cache
    • getSkin

      public static URL getSkin(String username)
      Gets the skin URL for the given player username.
      Parameters:
      username - the name of the player whose skin URL is to be retrieved
      Returns:
      the URL of the player's skin, or null if not found in the cache
    • removeProfile

      public static boolean removeProfile(String username)
      Removes a player's PlayerProfile from the cache.
      Parameters:
      username - the name of the player whose profile is to be removed
      Returns:
      true if the profile was successfully removed, false if it was not found in the cache