Revert to old createProfile(UUID, String) logic (#7723)

This commit is contained in:
Bjarne Koll 2022-04-22 20:54:08 +02:00
parent 16f92f9507
commit 0c85e94214
3 changed files with 81 additions and 9 deletions

View file

@ -301,7 +301,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Creates a PlayerProfile for the specified uuid, with name as null. + * 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 + * 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. + * be populated with the properties of said player (including their uuid and name).
+ * + *
+ * @param uuid UUID to create profile for + * @param uuid UUID to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
@ -315,7 +315,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Creates a PlayerProfile for the specified name, with UUID as null. + * 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 + * 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. + * be populated with the properties of said player (including their uuid and name).
+ * <p>
+ * 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)}.
+ * <p>
+ * + *
+ * @param name Name to create profile for + * @param name Name to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
@ -330,7 +335,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * + *
+ * Both UUID and Name can not be null at same time. One must be supplied. + * 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 + * 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. + * profile will be populated with the properties of said player (including their uuid and name).
+ * <p>
+ * 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)}.
+ * <p>
+ *
+ * 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 uuid UUID to create profile for
+ * @param name Name to create profile for + * @param name Name to create profile for
@ -339,6 +352,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ @NotNull + @NotNull
+ public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) { + public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) {
+ return server.createProfile(uuid, 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.
+ * <p>
+ * 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
+ */
+ @NotNull
+ public static com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name) {
+ return server.createProfileExact(uuid, name);
+ } + }
// Paper end // Paper end
@ -356,7 +389,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Creates a PlayerProfile for the specified uuid, with name as null. + * 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 + * 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. + * be populated with the properties of said player (including their uuid and name).
+ * + *
+ * @param uuid UUID to create profile for + * @param uuid UUID to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
@ -368,7 +401,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Creates a PlayerProfile for the specified name, with UUID as null. + * 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 + * 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. + * be populated with the properties of said player (including their uuid and name).
+ * <p>
+ * 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)}.
+ * <p>
+ * + *
+ * @param name Name to create profile for + * @param name Name to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
@ -381,7 +419,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * + *
+ * Both UUID and Name can not be null at same time. One must be supplied. + * 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 + * 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. + * profile will be populated with the properties of said player (including their uuid and name).
+ * <p>
+ * 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)}.
+ * <p>
+ *
+ * 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 uuid UUID to create profile for
+ * @param name Name to create profile for + * @param name Name to create profile for
@ -389,5 +435,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ */ + */
+ @NotNull + @NotNull
+ com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name); + 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.
+ * <p>
+ * 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
+ */
+ @NotNull
+ com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name);
// Paper end // Paper end
} }

View file

@ -9,8 +9,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/Bukkit.java --- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java +++ b/src/main/java/org/bukkit/Bukkit.java
@@ -0,0 +0,0 @@ public final class Bukkit { @@ -0,0 +0,0 @@ public final class Bukkit {
public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) { public static com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name) {
return server.createProfile(uuid, name); return server.createProfileExact(uuid, name);
} }
+ +
+ public static int getCurrentTick() { + public static int getCurrentTick() {
@ -26,7 +26,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi @@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/ */
@NotNull @NotNull
com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name); com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name);
+ +
+ /** + /**
+ * Get the current internal server tick + * Get the current internal server tick

View file

@ -660,6 +660,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ @Override + @Override
+ public com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) { + public com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) {
+ Player player = uuid != null ? Bukkit.getPlayer(uuid) : (name != null ? Bukkit.getPlayerExact(name) : null); + Player player = uuid != null ? Bukkit.getPlayer(uuid) : (name != null ? Bukkit.getPlayerExact(name) : null);
+ if (player != null) return new com.destroystokyo.paper.profile.CraftPlayerProfile((CraftPlayer) player);
+
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name);
+ }
+
+ @Override
+ public com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name) {
+ Player player = uuid != null ? Bukkit.getPlayer(uuid) : (name != null ? Bukkit.getPlayerExact(name) : null);
+ if (player == null) return new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name); + if (player == null) return new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name);
+ +
+ if (Objects.equals(uuid, player.getUniqueId()) && Objects.equals(name, player.getName())) { + if (Objects.equals(uuid, player.getUniqueId()) && Objects.equals(name, player.getName())) {