Class ProfileInstruction<T>
java.lang.Object
com.cryptomorin.xseries.profiles.builder.ProfileInstruction<T>
- Type Parameters:
T- The type of the result produced by theprofileContainerfunction.
- All Implemented Interfaces:
DelegateProfileable,Profileable
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.-
Nested Class Summary
Nested classes/interfaces inherited from interface com.cryptomorin.xseries.profiles.objects.Profileable
Profileable.GameProfileProfileable, Profileable.PlayerProfileable, Profileable.StringProfileable, Profileable.UsernameProfileable, Profileable.UUIDProfileable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply()Sets the profile generated by the instruction to the result type synchronously.@NotNull CompletableFuture<T> Asynchronously applies the instruction to generate aGameProfileand returns aCompletableFuture.@NotNull ProfileInstruction<T> fallback(@NotNull Profileable... fallbacks) A list of fallback profiles in order.The profileable object which handles all the operations.@Nullable com.mojang.authlib.GameProfileThe current profile of the item/block (not the profile provided inprofile(Profileable))@NotNull ProfileInstruction<T> lenient()Fails silently if any of theProfileExceptionerrors occur.@NotNull ProfileInstruction<T> onFallback(@NotNull Runnable onFallback) @NotNull ProfileInstruction<T> onFallback(@Nullable Consumer<ProfileFallback<T>> onFallback) Called when any of thefallback(Profileable...)profiles are used, this is also called if no fallback profile is provided, but the main oneprofile(Profileable)fails.@NotNull ProfileInstruction<T> profile(@NotNull Profileable profileable) Sets the texture profile to be set to the item/block.@NotNull ProfileInstruction<T> Removes the profile and skin texture from the item/block.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.cryptomorin.xseries.profiles.objects.DelegateProfileable
getDisposableProfile, getProfileValue, test, transform
-
Constructor Details
-
ProfileInstruction
-
-
Method Details
-
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
Fails silently if any of theProfileExceptionerrors occur. Mainly affectsProfileable.detect(String) -
getProfile
@Nullable public @Nullable com.mojang.authlib.GameProfile getProfile()The current profile of the item/block (not the profile provided inprofile(Profileable))- Specified by:
getProfilein interfaceDelegateProfileable- Specified by:
getProfilein interfaceProfileable- 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 forProfileContainer).
-
getDelegateProfile
Description copied from interface:DelegateProfileableThe profileable object which handles all the operations. It doesn't necessarily have to be a constant object, it can change dynamically.- Specified by:
getDelegateProfilein interfaceDelegateProfileable
-
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 ofProfileableclass. -
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 inprofile(Profileable)fails, these profiles will be tested in order until a correct one is found, also if any of the fallback profiles are used,onFallbackwill 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 thefallback(Profileable...)profiles are used, this is also called if no fallback profile is provided, but the main oneprofile(Profileable)fails.- See Also:
-
onFallback
@NotNull @Contract(value="_ -> this", mutates="this") public @NotNull ProfileInstruction<T> onFallback(@NotNull @NotNull Runnable onFallback) - See Also:
-
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 ofProfileExceptionoccurs, 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
Asynchronously applies the instruction to generate aGameProfileand returns aCompletableFuture. 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 exampleInventory.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
CompletableFuturethat will complete asynchronously.
-