Class SkullTexture
java.lang.Object
com.saicone.rtag.util.SkullTexture
- Direct Known Subclasses:
SkullTexture.CraftHead, SkullTexture.Mojang, SkullTexture.PlayerDB
Simple utility class to get textured heads from:
- Texture ID
- Texture URL
- Texture Base64
- Player
- Player name
- Player UUID
- Texture ID
- Texture URL
- Texture Base64
- Player
- Player name
- Player UUID
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCraftHead SkullTexture implementation that retrieves profiles using CraftHead API.static classMojang SkullTexture implementation that retrieves profiles using Mojang API.static classPlayerDB SkullTexture implementation that retrieves profiles using PlayerDB API.static classItem profile representation, can be static of dynamic profile. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.google.common.cache.Cache<String, SkullTexture.Profile> Cache object to save profiles.protected final ExecutorDefault executor to use on async operations. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a SkullTexture instance with default parameters.SkullTexture(@Nullable com.google.common.cache.Cache<String, SkullTexture.Profile> cache) Constructs a SkullTexture instance with provided cache object.SkullTexture(@Nullable com.google.common.cache.Cache<String, SkullTexture.Profile> cache, @NotNull Executor executor) Constructs a SkullTexture instance with provided cache object and executor.SkullTexture(@NotNull Executor executor) Constructs a SkullTexture instance with provided executor. -
Method Summary
Modifier and TypeMethodDescriptionprotected @NotNull SkullTexture.ProfileReturn profiles value from cache or save it by supplier.
If supplied value is null, this method will cache theSkullTexture.Profile.empty()object.static StringDeprecated.static StringcomputePlayerTexture(@NotNull String key, @NotNull String name) Deprecated.static SkullTextureGet a SkullTexture instance that retrieves texture values from CraftHead API by providing a player name or unique id.Encode provided texture url into minecraft profile property format.Get encoded texture value from minecraft texture ID.Get url data as json object.fetchProfile(@NotNull String name) Fetch profile value using player name.fetchProfile(@NotNull UUID uniqueId) Fetch profile value using player unique id.static @NotNull SkullTexture.ProfilegetProfile(@Nullable Player player) Get profile value from online player.static @NotNull SkullTexture.ProfilegetProfile(@Nullable ItemStack item) Get profile value from item.static ItemStackgetTexturedHead(String texture) Deprecated.static ItemStackgetTexturedHead(String texture, Consumer<ItemStack> callback) Deprecated.static StringgetTextureValue(String texture) Deprecated.static StringgetTextureValue(String texture, Consumer<String> callback) Deprecated.Get a player head with provided texture value.
This method may fetch textures using external APIs, use it in non-async operations if you know what are you doing.Get a player head asynchronously with provided texture value.
If encoded texture is already cached, a completed future will be return.Get a player head asynchronously with provided texture value and executor.
If encoded texture is already cached, a completed future will be return.static SkullTexturemojang()Get a SkullTexture instance that retrieves texture values from Mojang API by providing a player name or unique id.static SkullTextureplayerDB()Get a SkullTexture instance that retrieves texture values from PlayerDB API by providing a player name or unique id.profileFrom(@NotNull Object object) Get profile value from any supported object.
This method automatically caches the result to reduce request times.
Instead of other profile-getting methods, this method ignores any exception.profileFromId(@NotNull String uniqueId) Get profile value from player unique id.
This method accept raw ids without dashes.profileFromId(@NotNull UUID uniqueId) Get profile value from player unique id.profileFromName(@NotNull String name) Get profile value from player name.profileFromPlayer(@Nullable Player player) Get profile value from online player.profileSession(@NotNull com.google.gson.JsonObject session, @NotNull String idKey, @NotNull String nameKey) Parse profile session object as profile value.static StringrequestTextureUrl(@NotNull String name) Deprecated.setProfile(@NotNull ItemStack head, @NotNull SkullTexture.Profile profile) Set game profile value into skull meta.setTexture(@NotNull ItemStack head, @Nullable String texture) Set encoded texture value into skull meta.
-
Field Details
-
cache
Cache object to save profiles. -
executor
Default executor to use on async operations.
-
-
Constructor Details
-
SkullTexture
public SkullTexture()Constructs a SkullTexture instance with default parameters. -
SkullTexture
public SkullTexture(@Nullable @Nullable com.google.common.cache.Cache<String, SkullTexture.Profile> cache) Constructs a SkullTexture instance with provided cache object.- Parameters:
cache- the cache to save profiles.
-
SkullTexture
-
SkullTexture
public SkullTexture(@Nullable @Nullable com.google.common.cache.Cache<String, SkullTexture.Profile> cache, @NotNull @NotNull Executor executor) Constructs a SkullTexture instance with provided cache object and executor.- Parameters:
cache- the cache to save profiles.executor- the default executor to use in async operations.
-
-
Method Details
-
mojang
Get a SkullTexture instance that retrieves texture values from Mojang API by providing a player name or unique id.- Returns:
- a SkullTexture instance that use Mojang API.
-
playerDB
Get a SkullTexture instance that retrieves texture values from PlayerDB API by providing a player name or unique id.- Returns:
- a SkullTexture instance that use PlayerDB API.
-
craftHead
Get a SkullTexture instance that retrieves texture values from CraftHead API by providing a player name or unique id.- Returns:
- a SkullTexture instance that use PlayerDB API.
-
caching
@NotNull protected @NotNull SkullTexture.Profile caching(@NotNull @NotNull Object key, @NotNull @NotNull Supplier<SkullTexture.Profile> supplier) Return profiles value from cache or save it by supplier.
If supplied value is null, this method will cache theSkullTexture.Profile.empty()object.- Parameters:
key- the key to get texture from cache.supplier- the supplier that provide a non-cached value.- Returns:
- a cached profiles value,
SkullTexture.Profile.empty()if supplier return a null object.
-
item
Get a player head with provided texture value.
This method may fetch textures using external APIs, use it in non-async operations if you know what are you doing.- Parameters:
object- the object to convert into encoded texture, or the encoded texture itself.- Returns:
- a player head with provided texture value if found, normal head otherwise.
-
itemAsync
Get a player head asynchronously with provided texture value.
If encoded texture is already cached, a completed future will be return.- Parameters:
object- the object to convert into encoded texture, or the encoded texture itself.- Returns:
- a completable future containing player head with provided texture value if found, normal head otherwise.
-
itemAsync
@NotNull public @NotNull CompletableFuture<ItemStack> itemAsync(@NotNull @NotNull Object object, @NotNull @NotNull Executor executor) Get a player head asynchronously with provided texture value and executor.
If encoded texture is already cached, a completed future will be return.- Parameters:
object- the object to convert into encoded texture, or the encoded texture itself.executor- the executor to use for asynchronous execution- Returns:
- a completable future containing player head with provided texture value if found, normal head otherwise.
-
profileFrom
Get profile value from any supported object.
This method automatically caches the result to reduce request times.
Instead of other profile-getting methods, this method ignores any exception.- Parameters:
object- the object to convert into profile value, or the profile value itself.- Returns:
- a profile value if found and any error occurs,
SkullTexture.Profile.empty()otherwise.
-
profileFromPlayer
Get profile value from online player.- Parameters:
player- the online player.- Returns:
- a profile value,
SkullTexture.Profile.empty()if player texture cannot be found.
-
profileFromName
Get profile value from player name.- Parameters:
name- the player name.- Returns:
- a profile value,
SkullTexture.Profile.empty()if player texture cannot be found.
-
profileFromId
Get profile value from player unique id.
This method accept raw ids without dashes.- Parameters:
uniqueId- the player unique id.- Returns:
- a profile value,
SkullTexture.Profile.empty()if player texture cannot be found.
-
profileFromId
Get profile value from player unique id.- Parameters:
uniqueId- the player unique id.- Returns:
- a profile value,
SkullTexture.Profile.empty()if player texture cannot be found.
-
encodeUrl
-
encodeUrlId
-
fetchJson
-
fetchProfile
Fetch profile value using player name.- Parameters:
name- the player name to find.- Returns:
- a profile value if found,
SkullTexture.Profile.empty()otherwise.
-
fetchProfile
Fetch profile value using player unique id.- Parameters:
uniqueId- the unique id to find.- Returns:
- a profile value if found,
SkullTexture.Profile.empty()otherwise.
-
profileSession
@NotNull public @NotNull SkullTexture.Profile profileSession(@NotNull @NotNull com.google.gson.JsonObject session, @NotNull @NotNull String idKey, @NotNull @NotNull String nameKey) Parse profile session object as profile value.- Parameters:
session- the json object representation of player session.idKey- the key containing raw unique id.nameKey- the key containing player name.- Returns:
- a newly generated profile value.
-
setTexture
@NotNull @Contract("_, _ -> param1") public static @NotNull ItemStack setTexture(@NotNull @NotNull ItemStack head, @Nullable @Nullable String texture) throws IllegalArgumentException Set encoded texture value into skull meta.- Parameters:
head- skull item to set the texture.texture- encoded texture value.- Returns:
- the provided item.
- Throws:
IllegalArgumentException- if the provided item isn't a player head.
-
setProfile
@NotNull @Contract("_, _ -> param1") public static @NotNull ItemStack setProfile(@NotNull @NotNull ItemStack head, @NotNull @NotNull SkullTexture.Profile profile) throws IllegalArgumentException Set game profile value into skull meta.- Parameters:
head- skull item to set the profile.profile- profile value.- Returns:
- the provided item.
- Throws:
IllegalArgumentException- if the provided item isn't a player head.
-
getProfile
Get profile value from item.- Parameters:
item- the item to get the profile from.- Returns:
- a profile value,
SkullTexture.Profile.empty()if item is null o doesn't have profile.
-
getProfile
Get profile value from online player.- Parameters:
player- the player to get the profile from.- Returns:
- a profile value,
SkullTexture.Profile.empty()if player is null.
-
getTexturedHead
Deprecated.Main method to get textured head and save into cache.- Parameters:
texture- texture ID, URL, Base64, Player name or UUID.- Returns:
- a ItemStack that represent the textured head.
-
getTexturedHead
Deprecated.Main method to get textured head and save into cache.- Parameters:
texture- texture ID, URL, Base64, Player name or UUID.callback- function to execute if textured head is retrieved in async operation.- Returns:
- a ItemStack that represent the textured head.
-
getTextureValue
Deprecated.Get Base64 encoded texture from the given texture parameter, can be player name, player uuid, texture id, url or base64.- Parameters:
texture- texture type.- Returns:
- a Base64 encoded text.
-
getTextureValue
Deprecated.Get Base64 encoded texture from the given texture parameter, can be player name, player uuid, texture id, url or base64.- Parameters:
texture- texture type.callback- function to execute if texture value is retrieved in async operation.- Returns:
- a Base64 encoded text.
-
computePlayerTexture
Deprecated.Compute textured head via making a request to Mojang API, it's suggested to call this method in async environment.- Parameters:
name- the player name.- Returns:
- a Base64 encoded text.
-
computePlayerTexture
@Deprecated public static String computePlayerTexture(@NotNull @NotNull String key, @NotNull @NotNull String name) Deprecated.Compute textured head via making a request to Mojang API, it's suggested to call this method in async environment.- Parameters:
key- map key to put.name- the player name.- Returns:
- a Base64 encoded text.
-
requestTextureUrl
Deprecated.Request player texture url using Mojang API.- Parameters:
name- the player name.- Returns:
- a Mojang texture url if the player profile exists, null otherwise.
-
mojang().fetchProfile(String)instead.