Package valorless.havenbags.database
Class SkinCache
java.lang.Object
valorless.havenbags.database.SkinCache
- All Implemented Interfaces:
org.bukkit.event.Listener
This class is used to cache player skins and profiles.
It listens for player join events to update the cache and saves the cache to a file.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static valorless.valorlessutils.config.ConfigThe configuration object for the skin cache. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanup()Cleans up the cache by removing players who have no bags.getCache()Returns the cache of player profiles.static org.bukkit.profile.PlayerProfilegetProfile(String player) Gets the PlayerProfile for a given player name.static URLGets the skin URL for a given player name.static voidinit()Initializes the SkinCache by registering the event listener and loading the cache.voidonPlayerJoin(org.bukkit.event.player.PlayerJoinEvent e) Event handler for player join events.static voidshutdown()Saves the skin cache to the skins.yml file.
-
Field Details
-
config
protected static valorless.valorlessutils.config.Config configThe configuration object for the skin cache. This is a static Config object that is used to read and write the skins.yml file.
-
-
Constructor Details
-
SkinCache
public SkinCache()
-
-
Method Details
-
getCache
Returns the cache of player profiles. The cache is a HashMap where the key is the player's name and the value is their PlayerProfile.- Returns:
- HashMap<String, PlayerProfile> - The cache of player profiles.
-
init
public static void init()Initializes the SkinCache by registering the event listener and loading the cache. This method should be called when the plugin is enabled. -
shutdown
public static void shutdown()Saves the skin cache to the skins.yml file. This method is called on shutdown to ensure the cache is saved. -
cleanup
public static void cleanup()Cleans up the cache by removing players who have no bags. This is called on shutdown to ensure the cache only contains players with bags. -
onPlayerJoin
public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent e) Event handler for player join events. When a player joins, their profile is added to the cache.- Parameters:
e- The PlayerJoinEvent that is triggered when a player joins the server.
-
getProfile
Gets the PlayerProfile for a given player name.- Parameters:
player- The name of the player whose profile is to be retrieved.- Returns:
- PlayerProfile - The PlayerProfile of the specified player, or null if not found.
-
getSkin
Gets the skin URL for a given player name.- Parameters:
player- The name of the player whose skin URL is to be retrieved.- Returns:
- URL - The URL of the player's skin, or null if not found.
-