Interface Profileable

All Known Subinterfaces:
DelegateProfileable
All Known Implementing Classes:
CacheableProfileable, Profileable.DynamicGameProfileProfileable, Profileable.PlayerProfileable, Profileable.PlayerProfileProfileable, Profileable.RawGameProfileProfileable, Profileable.StringProfileable, Profileable.UsernameProfileable, Profileable.UUIDProfileable, ProfileContainer, ProfileContainer.BlockProfileContainer, ProfileContainer.BlockStateProfileContainer, ProfileContainer.ItemMetaProfileContainer, ProfileContainer.ItemStackProfileContainer, ProfileInstruction, TimedCacheableProfileable, TransformableProfile

public interface Profileable
Represents any object that has a GameProfile or one can be created with it. These objects are cached.

Usually this class is intended to be used with XSkull by defining the profile to set for ProfileInstruction.profile(Profileable), however it can be used by itself for more advanced systems if you know what you're doing.

A GameProfile is an object that represents information about a Minecraft player's account in general (not specific to this or any other server) The most important information contained within this profile however, is the skin texture URL which the client needs to properly see the texture on items/blocks. The server itself doesn't process the texture from the URL, it gives it to the client for it to download and process the texture instead.

See Also:
  • Method Details

    • getProfile

      @Nullable @Internal @Nullable @Unmodifiable com.mojang.authlib.GameProfile getProfile()
      This method should not be used directly unless you know what you're doing.

      The texture which might be cached. If any errors occur, the check may be re-evaluated. The cached values might also be re-evaluated due to expiration.

      Returns:
      the original profile (not cloned if possible) for an instance that's always guaranteed to be a copy you can use getDisposableProfile() instead. Null if no profile is set (only happens for ProfileContainer).
      Throws:
      ProfileException - may also throw other internal exceptions (most likely bugs)
    • isReady

      @Contract(pure=true) boolean isReady()
      Whether this profile has all the necessary information to construct its getProfile() right away. When this method returns false, it means some kind of request has to be sent to Mojang servers in order to retrieve some information.

      Even if this method returns true, it doesn't necessarily mean that this profile has all information (textures, username, UUID, etc.) it merely means that it has all the information it needs in memory to compute its getProfile() and doesn't need to a request any data using MinecraftClient.

      Since:
      12.0.0
      See Also:
    • test

      @Nullable @Contract("-> new") default @Nullable ProfileException test()
      Tests whether this profile has any issues or throws any exception. This is a good way if you're going to be checking for user issues before trying to ProfileInstruction.apply() them. For now, this is basically equivalent to calling getProfile() and catching exceptions. Which means that the profile will be cached if a cache is behind this profile.

      These issues include, wrong username, network issues, etc. Note that some issues only occur when ProfileInstruction.apply() is used. Any other type of exception that might happen are still ignored.

    • getDisposableProfile

      @Nullable @Internal @Contract("-> new") default @Nullable com.mojang.authlib.GameProfile getDisposableProfile()
      Same as getProfile(), except some implementations of Profileable cannot inherently return any original instance as they're not cacheable, so this method ensures that no duplicate cloning of GameProfile occurs for performance.

      For most implementations however, this defaults to a simple cloning of the cached instances.

      Returns:
      always a copied version of getProfile() that you can change. Null if getProfile() is null
    • transform

      @NotNull @Contract(value="_ -> new", pure=true) default @NotNull Profileable transform(@NotNull @NotNull ProfileTransformer... transformers)
      Adds transformer (read ProfileTransformer) information to a copied version of this profile (so it doesn't affect this instance, but the class type will change). So it's recommended to not chain this method and instead collect all transformers and call this method once for performance when necessary.

      Profiles are copied before being transformed, so the main cache remains intact but the result of transformed profiles are never cached.

      Parameters:
      transformers - a list of transformers to apply in order once getProfile() is called.
    • getProfileValue

      @Nullable default @Nullable String getProfileValue()
      A string representation of the getProfile() which is useful for data storage which can be serialized back using detect(String).

      Note that in some cases this is the Base64 value of the textures property, but some may provide less verbose data when possible. Items and blocks can also provide compact data if their profile was built using ProfileTransformer.includeOriginalValue().

      Returns:
      null if getProfile() is null or the set profile doesn't have a texture property.
    • prepare

      @NotNull @Contract("-> new") @Experimental default @NotNull CompletableFuture<Profileable> prepare()
      A single version of prepare(Collection, ProfileRequestConfiguration, Function). This simply performs profile lookup asynchrously and returns after it's done, or it will instantly return if isReady() is true.

      Remember to handle errors using CompletableFuture.exceptionally(java.util.function.Function) or other error handling methods, CompletableFutures will "eat" errors without printing them when it's not handled manually.

      Returns:
      A future containing the same object.
      Since:
      12.0.0
    • prepare

      @NotNull @Contract("_ -> new") @Experimental static <C extends Collection<Profileable>> @NotNull CompletableFuture<C> prepare(@NotNull C profileables)
      See Also:
    • prepare

      @NotNull @Contract("_, _, _ -> new") @Experimental static <C extends Collection<Profileable>> @NotNull CompletableFuture<C> prepare(@NotNull C profileables, @Nullable @Nullable ProfileRequestConfiguration config, @Nullable @Nullable com.google.common.base.Function<Throwable,Boolean> errorHandler)
      Prepares the given profiles asynchrously with the given settings.
      Type Parameters:
      C - the type of the collection used for the profiles.
      Parameters:
      profileables - the collect of profiles to prepare.
      config - How requests to Mojang servers are handled if any are necessary.
      errorHandler - how to handle errors that occur for each of the profiles individually. If the error handler returns true, the entire operation will fail exceptionally, otherwise that specific profile will be ignored.
      Returns:
      the same collection unmodified. (The profiles are cached inside the Profileable itself, so you can use them directly now)
      See Also:
    • username

      @NotNull @Contract(pure=true) static @NotNull Profileable username(@NotNull @NotNull String username)
      Sets the skull texture based on the specified player UUID (whether it's an offline or online UUID).
    • of

      @NotNull @Contract(pure=true) static @NotNull Profileable of(@NotNull @NotNull UUID uuid)
      Sets the skull texture based on the specified player UUID (whether it's an offline or online UUID).
    • of

      @NotNull @Contract(pure=true) static @NotNull Profileable of(@NotNull @NotNull com.mojang.authlib.GameProfile profile, boolean fetchTexturesIfNeeded)
      Sets the skull texture based on the specified profile. If the profile already has textures, it will be used directly. Otherwise, a new profile will be fetched based on the UUID or username depending on the server's online mode.
      Parameters:
      profile - The profile to be used in the profile setting operation.
      fetchTexturesIfNeeded - whether textures should be automatically fetched for this profile if they don't exist. This should almost always be set to true unless you want some other code to handle the texture (whether server-side or client-side.)
    • of

      @NotNull @Contract(pure=true) static @NotNull Profileable of(@NotNull @NotNull org.bukkit.OfflinePlayer offlinePlayer)
      Sets the skull texture based on the specified offline player. The profile lookup will depend on whether the server is running in online mode or not that's why this method accepts an OfflinePlayer not a Player.
      Parameters:
      offlinePlayer - The offline player to generate the GameProfile.
    • of

      @NotNull @Contract(pure=true) static @NotNull Profileable of(@NotNull @NotNull org.bukkit.block.BlockState blockState)
      Gets the skull texture from a block that is Skull.
      See Also:
    • of

      @NotNull @Contract(pure=true) static @NotNull Profileable of(@NotNull @NotNull org.bukkit.block.Block block)
      Gets the skull texture from a block that is Skull.
      See Also:
    • of

      @NotNull @Contract(pure=true) static @NotNull Profileable of(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Gets the skull texture from an item which is a XMaterial.PLAYER_HEAD.
      See Also:
    • of

      @NotNull @Contract(pure=true) static @NotNull Profileable of(@NotNull @NotNull org.bukkit.inventory.meta.ItemMeta meta)
      Gets the skull texture from an item which is a XMaterial.PLAYER_HEAD.
      See Also:
    • detect

      @NotNull @Contract(pure=true) static @NotNull Profileable detect(@NotNull @NotNull String input)
      Sets the skull texture based on a string. The input type is resolved based on the value provided.

      Valid Types

      Username: A player username. (e.g. Notch)
      UUID: A player UUID. Offline or online mode UUID. (e.g. 069a79f4-44e9-4726-a5be-fca90e38aaf5)
      Base64: The Base64 encoded value of textures JSON. (e.g. eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2NmNjc2N2RkMzQ3MzdlOTliZDU0YjY5NWVmMDY4M2M2YzZjZTZhNTRmNjZhZDk3Mjk5MmJkMGU0OGU0NTc5YiJ9fX0=)
      Minecraft Textures URL: Check ProfileInputType.TEXTURE_URL.
      Minecraft Textures Hash: Same as the URL, but only including the hash part, excluding the base URL. (e.g. e5461a215b325fbdf892db67b7bfb60ad2bf1580dc968a15dfb304ccd5e74db)
      Parameters:
      input - The input value used to retrieve the GameProfile. For more information check ProfileInputType
    • of

      @NotNull @Contract(pure=true) static @NotNull Profileable of(@NotNull @NotNull ProfileInputType type, @NotNull @NotNull String input)
      Sets the skull texture based on a string with a known type.
      Parameters:
      type - The type of the input value.
      input - The input value to generate the GameProfile.