null
+ */
+ @Override
+ PlayerTextures getTextures();
+
+ /**
+ * Copies the given textures.
+ *
+ * @param textures the textures to copy, or null to clear the
+ * textures
+ */
+ @Override
+ void setTextures(@Nullable PlayerTextures textures);
+
+ /**
+ * @return A Mutable set of this players properties, such as textures.
+ * Values specified here are subject to implementation details.
+ */
+ Set+ * This will also complete textures. If you do not want to load textures, use {{@link #complete(boolean)}} + * + * @return If the profile is now complete (has UUID and Name) (if you get rate limited, this operation may fail) + */ + default boolean complete() { + return this.complete(true); + } + + /** + * If this profile is not complete, then make the API call to complete it. + * This is a blocking operation and should be done asynchronously. + *
+ * Optionally will also fill textures. + *
+ * Online mode will be automatically determined + * + * @param textures controls if we should fill the profile with texture properties + * @return If the profile is now complete (has UUID and Name) (if you get rate limited, this operation may fail) + */ + boolean complete(boolean textures); + + /** + * If this profile is not complete, then make the API call to complete it. + * This is a blocking operation and should be done asynchronously. + *
+ * Optionally will also fill textures. + * + * @param textures controls if we should fill the profile with texture properties + * @param onlineMode Treat this server as online mode or not + * @return If the profile is now complete (has UUID and Name) (if you get rate limited, this operation may fail) + */ + boolean complete(boolean textures, boolean onlineMode); + + /** + * Produces an updated player profile based on this profile. + *
+ * This tries to produce a completed profile by filling in missing + * properties (name, unique id, textures, etc.), and updates existing + * properties (e.g. name, textures, etc.) to their official and up-to-date + * values. This operation does not alter the current profile, but produces a + * new updated {@link PlayerProfile}. + *
+ * If no player exists for the unique id or name of this profile, this + * operation yields a profile that is equal to the current profile, which + * might not be complete. + *
+ * This is an asynchronous operation: Updating the profile can result in an + * outgoing connection in another thread in order to fetch the latest + * profile properties. The returned {@link CompletableFuture} will be + * completed once the updated profile is available. In order to not block + * the server's main thread, you should not wait for the result of the + * returned CompletableFuture on the server's main thread. Instead, if you + * want to do something with the updated player profile on the server's main + * thread once it is available, you could do something like this: + *
+ * profile.update().thenAcceptAsync(updatedProfile -> {
+ * // Do something with the updated profile:
+ * // ...
+ * }, runnable -> Bukkit.getScheduler().runTask(plugin, runnable));
+ *
+ */
+ @Override
+ CompletableFuture+ * E.g. if the player 'jeb_' is currently playing on the server, calling {@code createProfile("JEB_")} will + * yield a profile with the name 'jeb_', their uuid and their textures. + * To bypass this pre-population on a case-insensitive name match, see {@link #createProfileExact(UUID, String)}. + *
+ * + * @param name Name to create profile for + * @return A PlayerProfile object + * @throws IllegalArgumentException if the name is longer than 16 characters + * @throws IllegalArgumentException if the name contains invalid characters + */ + @NotNull + public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull String name) { + return server.createProfile(name); + } + + /** + * Creates a PlayerProfile for the specified name/uuid + * + * Both UUID and Name can not be null at same time. One must be supplied. + * If a player with the passed uuid or name exists on the server at the time of creation, the returned player + * profile will be populated with the properties of said player (including their uuid and name). + *
+ * E.g. if the player 'jeb_' is currently playing on the server, calling {@code createProfile(null, "JEB_")} will + * yield a profile with the name 'jeb_', their uuid and their textures. + * To bypass this pre-population on an case-insensitive name match, see {@link #createProfileExact(UUID, String)}. + *
+ * + * The name comparison will compare the {@link String#toLowerCase()} version of both the passed name parameter and + * a players name to honour the case-insensitive nature of a mojang profile lookup. + * + * @param uuid UUID to create profile for + * @param name Name to create profile for + * @return A PlayerProfile object + * @throws IllegalArgumentException if the name is longer than 16 characters + * @throws IllegalArgumentException if the name contains invalid characters + */ + @NotNull + public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) { + return server.createProfile(uuid, name); + } + + /** + * Creates an exact PlayerProfile for the specified name/uuid + * + * Both UUID and Name can not be null at same time. One must be supplied. + * If a player with the passed uuid or name exists on the server at the time of creation, the returned player + * profile will be populated with the properties of said player. + *
+ * Compared to {@link #createProfile(UUID, String)}, this method will never mutate the passed uuid or name. + * If a player with either the same uuid or a matching name (case-insensitive) is found on the server, their + * properties, such as textures, will be pre-populated in the profile, however the passed uuid and name stay intact. + * + * @param uuid UUID to create profile for + * @param name Name to create profile for + * @return A PlayerProfile object + * @throws IllegalArgumentException if the name is longer than 16 characters + * @throws IllegalArgumentException if the name contains invalid characters + */ + @NotNull + public static com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name) { + return server.createProfileExact(uuid, name); + } // Paper end @NotNull diff --git a/paper-api/src/main/java/org/bukkit/Server.java b/paper-api/src/main/java/org/bukkit/Server.java index a506e6184..51bed70fd 100644 --- a/paper-api/src/main/java/org/bukkit/Server.java +++ b/paper-api/src/main/java/org/bukkit/Server.java @@ -2108,5 +2108,80 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi * @return true if player names should be suggested */ boolean suggestPlayerNamesWhenNullTabCompletions(); + + /** + * Creates a PlayerProfile for the specified uuid, with name as null. + * + * If a player with the passed uuid exists on the server at the time of creation, the returned player profile will + * be populated with the properties of said player (including their uuid and name). + * + * @param uuid UUID to create profile for + * @return A PlayerProfile object + */ + @NotNull + com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull UUID uuid); + + /** + * Creates a PlayerProfile for the specified name, with UUID as null. + * + * If a player with the passed name exists on the server at the time of creation, the returned player profile will + * be populated with the properties of said player (including their uuid and name). + *
+ * E.g. if the player 'jeb_' is currently playing on the server, calling {@code createProfile("JEB_")} will + * yield a profile with the name 'jeb_', their uuid and their textures. + * To bypass this pre-population on a case-insensitive name match, see {@link #createProfileExact(UUID, String)}. + *
+ * + * @param name Name to create profile for + * @return A PlayerProfile object + * @throws IllegalArgumentException if the name is longer than 16 characters + * @throws IllegalArgumentException if the name contains invalid characters + */ + @NotNull + com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull String name); + + /** + * Creates a PlayerProfile for the specified name/uuid + * + * Both UUID and Name can not be null at same time. One must be supplied. + * If a player with the passed uuid or name exists on the server at the time of creation, the returned player + * profile will be populated with the properties of said player (including their uuid and name). + *
+ * E.g. if the player 'jeb_' is currently playing on the server, calling {@code createProfile(null, "JEB_")} will + * yield a profile with the name 'jeb_', their uuid and their textures. + * To bypass this pre-population on an case-insensitive name match, see {@link #createProfileExact(UUID, String)}. + *
+ * + * The name comparison will compare the {@link String#toLowerCase()} version of both the passed name parameter and + * a players name to honour the case-insensitive nature of a mojang profile lookup. + * + * @param uuid UUID to create profile for + * @param name Name to create profile for + * @return A PlayerProfile object + * @throws IllegalArgumentException if the name is longer than 16 characters + * @throws IllegalArgumentException if the name contains invalid characters + */ + @NotNull + com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name); + + /** + * Creates an exact PlayerProfile for the specified name/uuid + * + * Both UUID and Name can not be null at same time. One must be supplied. + * If a player with the passed uuid or name exists on the server at the time of creation, the returned player + * profile will be populated with the properties of said player. + *
+ * Compared to {@link #createProfile(UUID, String)}, this method will never mutate the passed uuid or name.
+ * If a player with either the same uuid or a matching name (case-insensitive) is found on the server, their
+ * properties, such as textures, will be pre-populated in the profile, however the passed uuid and name stay intact.
+ *
+ * @param uuid UUID to create profile for
+ * @param name Name to create profile for
+ * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */
+ @NotNull
+ com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name);
// Paper end
}
diff --git a/paper-api/src/main/java/org/bukkit/profile/PlayerProfile.java b/paper-api/src/main/java/org/bukkit/profile/PlayerProfile.java
index 16ae1282f..fc46add38 100644
--- a/paper-api/src/main/java/org/bukkit/profile/PlayerProfile.java
+++ b/paper-api/src/main/java/org/bukkit/profile/PlayerProfile.java
@@ -93,7 +93,7 @@ public interface PlayerProfile extends Cloneable, ConfigurationSerializable {
* PlayerProfile once it is available
*/
@NotNull
- CompletableFuture