Class ProfileInstruction<T>

java.lang.Object
com.cryptomorin.xseries.profiles.builder.ProfileInstruction<T>
Type Parameters:
T - The type of the result produced by the profileContainer function.
All Implemented Interfaces:
DelegateProfileable, Profileable

public final class ProfileInstruction<T> extends Object implements DelegateProfileable
Represents an instruction that sets a property of a GameProfile. It uses a profileContainer to define how to set the property and a profileable to define what to set in the property.
  • Constructor Details

    • ProfileInstruction

      protected ProfileInstruction(ProfileContainer<T> profileContainer)
  • Method Details

    • removeProfile

      @NotNull @Contract(mutates="this") public T removeProfile()
      Removes the profile and skin texture from the item/block.
    • profileRequestConfiguration

      @Experimental @NotNull @Contract(value="_ -> this", mutates="this") public @NotNull ProfileInstruction<T> profileRequestConfiguration(ProfileRequestConfiguration config)
    • lenient

      @NotNull @Contract(value="-> this", mutates="this") public @NotNull ProfileInstruction<T> lenient()
      Fails silently if any of the ProfileException errors occur. Mainly affects Profileable.detect(String)
    • getProfile

      @Nullable public @Nullable com.mojang.authlib.GameProfile getProfile()
      The current profile of the item/block (not the profile provided in profile(Profileable))
      Specified by:
      getProfile in interface DelegateProfileable
      Specified by:
      getProfile in interface Profileable
      Returns:
      the original profile (not cloned if possible) for an instance that's always guaranteed to be a copy you can use Profileable.getDisposableProfile() instead. Null if no profile is set (only happens for ProfileContainer).
    • getDelegateProfile

      @Contract(pure=true) public Profileable getDelegateProfile()
      Description copied from interface: DelegateProfileable
      The profileable object which handles all the operations. It doesn't necessarily have to be a constant object, it can change dynamically.
      Specified by:
      getDelegateProfile in interface DelegateProfileable
    • profile

      @NotNull @Contract(value="_ -> this", mutates="this") public @NotNull ProfileInstruction<T> profile(@NotNull @NotNull Profileable profileable)
      Sets the texture profile to be set to the item/block. Use one of the static methods of Profileable class.
    • fallback

      @NotNull @Contract(value="_ -> this", mutates="this") public @NotNull ProfileInstruction<T> fallback(@NotNull @NotNull Profileable... fallbacks)
      A list of fallback profiles in order. If the profile set in profile(Profileable) fails, these profiles will be tested in order until a correct one is found, also if any of the fallback profiles are used, onFallback will be called too.
      See Also:
    • onFallback

      @NotNull @Contract(value="_ -> this", mutates="this") public @NotNull ProfileInstruction<T> onFallback(@Nullable @Nullable Consumer<ProfileFallback<T>> onFallback)
      Called when any of the fallback(Profileable...) profiles are used, this is also called if no fallback profile is provided, but the main one profile(Profileable) fails.
      See Also:
    • onFallback

      @NotNull @Contract(value="_ -> this", mutates="this") public @NotNull ProfileInstruction<T> onFallback(@NotNull @NotNull Runnable onFallback)
      See Also:
    • apply

      @NotNull public T apply()
      Sets the profile generated by the instruction to the result type synchronously. This is recommended if your code is already not on the main thread, or if you know that the skull texture doesn't need additional requests.

      What are these additional requests?

      This only applies to offline mode (cracked) servers. Since these servers use a cracked version of the player UUIDs and not their real ones, the real UUID needs to be known by requesting it from Mojang servers and this request which requires internet connection, will delay things a lot.
      Returns:
      The result after setting the generated profile.
      Throws:
      ProfileChangeException - If any type of ProfileException occurs, they will be accumulated in form of suppressed exceptions (Throwable.getSuppressed()) in this single exception starting from the main profile, followed by the fallback profiles.
    • applyAsync

      @NotNull public @NotNull CompletableFuture<T> applyAsync()
      Asynchronously applies the instruction to generate a GameProfile and returns a CompletableFuture. This method is designed for non-blocking execution, allowing tasks to be performed in the background without blocking the server's main thread. This method will always execute async, even if the results are cached.

      Reference Issues

      Note that while these methods apply to the item/block instances, passing these instances to certain methods, for example Inventory.setItem(int, ItemStack) will create a NMS copy of that instance and use that instead. Which means if for example you're going to be using an item for an inventory, you'd have to set the item again manually to the inventory once this method is done.
      
       Inventory inventory = ...;
       XSkull.createItem().profile(player).applyAsync()
           .thenAcceptAsync(item -> inventory.setItem(slot, item));
       

      To make this cleaner, you could change the first line of the item's lore to something like "Loading..." and set it to the inventory right away so the player knows that the data is not fully loaded. Once this method is done, you could change the lore back and set the item back to the inventory. (The lore is preferred because it has less text limit compared to the title, it also gives the player all the textual information they need rather than the visual information if you're in a hurry)


      Usage example:

      
         XSkull.createItem().profile(player).applyAsync()
            .thenAcceptAsync(result -> {
                // Additional processing...
            }, runnable -> Bukkit.getScheduler().runTask(plugin, runnable));
       
      Returns:
      A CompletableFuture that will complete asynchronously.