Package dev.majek.pc.util
Class SkullCache
- java.lang.Object
-
- dev.majek.pc.util.SkullCache
-
public class SkullCache extends Object
Handles fetching and caching player skulls for easier use in GUIs.
-
-
Constructor Summary
Constructors Constructor Description SkullCache()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcacheSkull(UUID uuid)Cache a skull from a uuid.static voidcacheSkull(org.bukkit.entity.Player player)Cache a skull from an online player.static voidcacheSkull(org.bukkit.OfflinePlayer offlinePlayer)Cache a skull from an offline player.static voidcacheSkulls(UUID[] uuids)Cache an array of skulls from uuids.static voidcacheSkulls(org.bukkit.entity.Player[] players)Cache an array of skulls from online players.static voidcacheSkulls(org.bukkit.OfflinePlayer[] offlinePlayers)Cache an array of skulls from offline players.static org.bukkit.inventory.ItemStackcreateSkull()Creates a new player head item stack.static voidflush(long milliseconds)Remove skulls from memory if they haven't been cached or accessed within the specified amount of time.static voidflushWeek()Remove skulls from memory that haven't been cached or accessed within a week.static org.bukkit.inventory.ItemStackgetSkull(UUID uuid)Get a skull from a uuid.static org.bukkit.inventory.ItemStackgetSkull(org.bukkit.entity.Player player)Get a skull from an online player.static org.bukkit.inventory.ItemStackgetSkull(org.bukkit.OfflinePlayer offlinePlayer)Get a skull from an offline player.static org.bukkit.inventory.ItemStack[]getSkulls(UUID[] uuids)Get an array of player skulls from uuids.static org.bukkit.inventory.ItemStack[]getSkulls(org.bukkit.entity.Player[] players)Get an array of online player skulls from online players.static org.bukkit.inventory.ItemStack[]getSkulls(org.bukkit.OfflinePlayer[] offlinePlayers)Get an array of offline player skulls from offline players.static org.bukkit.inventory.ItemStackitemWithUuid(org.bukkit.inventory.ItemStack item, UUID id)Modifies a skull to use the skin of the player with a given uuid.static org.bukkit.inventory.ItemStackskullFromUuid(UUID id)Creates a player skull item with the skin based on a player's UUID.
-
-
-
Method Detail
-
cacheSkull
public static void cacheSkull(UUID uuid)
Cache a skull from a uuid.- Parameters:
uuid- The player's uuid.
-
cacheSkull
public static void cacheSkull(org.bukkit.OfflinePlayer offlinePlayer)
Cache a skull from an offline player.- Parameters:
offlinePlayer- The offline player.
-
cacheSkull
public static void cacheSkull(org.bukkit.entity.Player player)
Cache a skull from an online player.- Parameters:
player- The online player.
-
cacheSkulls
public static void cacheSkulls(UUID[] uuids)
Cache an array of skulls from uuids. Task will run asynchronously in an attempt to prevent server lag.- Parameters:
uuids- Array of uuids.
-
cacheSkulls
public static void cacheSkulls(org.bukkit.OfflinePlayer[] offlinePlayers)
Cache an array of skulls from offline players.- Parameters:
offlinePlayers- Array of offline players.
-
cacheSkulls
public static void cacheSkulls(org.bukkit.entity.Player[] players)
Cache an array of skulls from online players.- Parameters:
players- Array of online players.
-
getSkull
public static org.bukkit.inventory.ItemStack getSkull(UUID uuid)
Get a skull from a uuid. If the skull is not saved in memory it will be fetched from Mojang and then cached for future use.- Parameters:
uuid- The player's uuid.- Returns:
- ItemStack of the player's skull.
-
getSkull
public static org.bukkit.inventory.ItemStack getSkull(org.bukkit.OfflinePlayer offlinePlayer)
Get a skull from an offline player. If the skull is not saved in memory it will be fetched from Mojang and then cached for future use.- Parameters:
offlinePlayer- The offline player.- Returns:
- ItemStack of the offline player's skull.
-
getSkull
public static org.bukkit.inventory.ItemStack getSkull(org.bukkit.entity.Player player)
Get a skull from an online player. If the skull is not saved in memory it will be fetched from Mojang and then cached for future use.- Parameters:
player- The online player.- Returns:
- ItemStack of the online player's skull.
-
getSkulls
public static org.bukkit.inventory.ItemStack[] getSkulls(UUID[] uuids)
Get an array of player skulls from uuids.- Parameters:
uuids- Array of uuids.- Returns:
- ItemStack array of skulls.
-
getSkulls
public static org.bukkit.inventory.ItemStack[] getSkulls(org.bukkit.OfflinePlayer[] offlinePlayers)
Get an array of offline player skulls from offline players.- Parameters:
offlinePlayers- Array of offline players.- Returns:
- ItemStack array of skulls.
-
getSkulls
public static org.bukkit.inventory.ItemStack[] getSkulls(org.bukkit.entity.Player[] players)
Get an array of online player skulls from online players.- Parameters:
players- Array of online players.- Returns:
- ItemStack array of skulls.
-
flush
public static void flush(long milliseconds)
Remove skulls from memory if they haven't been cached or accessed within the specified amount of time.- Parameters:
milliseconds- Duration of time given in milliseconds.
-
flushWeek
public static void flushWeek()
Remove skulls from memory that haven't been cached or accessed within a week.
-
createSkull
public static org.bukkit.inventory.ItemStack createSkull()
Creates a new player head item stack.- Returns:
- Player head.
-
skullFromUuid
public static org.bukkit.inventory.ItemStack skullFromUuid(UUID id)
Creates a player skull item with the skin based on a player's UUID.- Parameters:
id- The player's UUID.- Returns:
- The head of the player.
-
itemWithUuid
public static org.bukkit.inventory.ItemStack itemWithUuid(org.bukkit.inventory.ItemStack item, UUID id) throws ExceptionModifies a skull to use the skin of the player with a given uuid.- Parameters:
item- The item to apply the name to. Must be a player skull.id- The player's uuid.- Returns:
- The head of the player.
- Throws:
Exception- if the player is not found
-
-