From 6b895464b0a4b6c4cfe7b6d763b9ffe23c37bba6 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Sat, 19 Mar 2022 14:39:38 +0100 Subject: [PATCH] Properly create profiles with custom name/uuid (#7558) --- patches/api/Basic-PlayerProfile-API.patch | 28 ++++++++++++++++--- ...ault-permission-message-configurable.patch | 8 +++--- patches/server/Basic-PlayerProfile-API.patch | 11 ++++++-- .../Expose-the-internal-current-tick.patch | 4 +-- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/patches/api/Basic-PlayerProfile-API.patch b/patches/api/Basic-PlayerProfile-API.patch index 7d141b8a1e..8723ca669a 100644 --- a/patches/api/Basic-PlayerProfile-API.patch +++ b/patches/api/Basic-PlayerProfile-API.patch @@ -298,7 +298,11 @@ 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 ++ * be populated with the properties of said player. ++ * + * @param uuid UUID to create profile for + * @return A PlayerProfile object + */ @@ -308,7 +312,11 @@ 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 ++ * be populated with the properties of said player. ++ * + * @param name Name to create profile for + * @return A PlayerProfile object + */ @@ -321,6 +329,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * 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. + * + * @param uuid UUID to create profile for + * @param name Name to create profile for @@ -343,7 +353,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 boolean suggestPlayerNamesWhenNullTabCompletions(); + + /** -+ * 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 ++ * be populated with the properties of said player. ++ * + * @param uuid UUID to create profile for + * @return A PlayerProfile object + */ @@ -351,7 +365,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull UUID uuid); + + /** -+ * 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 ++ * be populated with the properties of said player. ++ * + * @param name Name to create profile for + * @return A PlayerProfile object + */ @@ -362,6 +380,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * 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. + * + * @param uuid UUID to create profile for + * @param name Name to create profile for diff --git a/patches/api/Make-the-default-permission-message-configurable.patch b/patches/api/Make-the-default-permission-message-configurable.patch index 45e468aee0..ad25ffa9fc 100644 --- a/patches/api/Make-the-default-permission-message-configurable.patch +++ b/patches/api/Make-the-default-permission-message-configurable.patch @@ -22,8 +22,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + /** - * Creates a PlayerProfile for the specified uuid, with name as null - * @param uuid UUID to create profile for + * Creates a PlayerProfile for the specified uuid, with name as null. + * diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/Server.java @@ -40,8 +40,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + String getPermissionMessage(); + /** - * Creates a PlayerProfile for the specified uuid, with name as null - * @param uuid UUID to create profile for + * Creates a PlayerProfile for the specified uuid, with name as null. + * diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/command/Command.java diff --git a/patches/server/Basic-PlayerProfile-API.patch b/patches/server/Basic-PlayerProfile-API.patch index aeb760dfde..c8c9654bb8 100644 --- a/patches/server/Basic-PlayerProfile-API.patch +++ b/patches/server/Basic-PlayerProfile-API.patch @@ -660,10 +660,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @Override + 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); -+ if (player != null) { -+ return new com.destroystokyo.paper.profile.CraftPlayerProfile((CraftPlayer)player); ++ if (player == null) return new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name); ++ ++ if (Objects.equals(uuid, player.getUniqueId()) && Objects.equals(name, player.getName())) { ++ return new com.destroystokyo.paper.profile.CraftPlayerProfile((CraftPlayer) player); + } -+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name); ++ ++ final com.mojang.authlib.GameProfile profile = new com.mojang.authlib.GameProfile(uuid, name); ++ profile.getProperties().putAll(((CraftPlayer)player).getHandle().getGameProfile().getProperties()); ++ return new com.destroystokyo.paper.profile.CraftPlayerProfile(profile); + } // Paper end } diff --git a/patches/server/Expose-the-internal-current-tick.patch b/patches/server/Expose-the-internal-current-tick.patch index 2b33037f5c..e70c4d59b5 100644 --- a/patches/server/Expose-the-internal-current-tick.patch +++ b/patches/server/Expose-the-internal-current-tick.patch @@ -9,8 +9,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -0,0 +0,0 @@ public final class CraftServer implements Server { - } - return new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name); + profile.getProperties().putAll(((CraftPlayer)player).getHandle().getGameProfile().getProperties()); + return new com.destroystokyo.paper.profile.CraftPlayerProfile(profile); } + + @Override