Only fetch an online UUID in online mode

The previous code would get an online UUID even in offline mode that
breaks plugins if the player joins.

Example: You want to store data for player "Test" who never joined. An
online UUID is created and you save it using that UUID.

The player Test joins with an offline UUID but that will not match the
online UUID of the saved data.

Adapted from Spigot commit 25b673fd7e418e21eb445a9e39d51baa0c0ab8b6
This commit is contained in:
Maxim Van de Wynckel 2023-12-31 10:46:30 +11:00 committed by md_5
parent 1da8d9a53a
commit 6902782005
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -1746,8 +1746,13 @@ public final class CraftServer implements Server {
OfflinePlayer result = getPlayerExact(name); OfflinePlayer result = getPlayerExact(name);
if (result == null) { if (result == null) {
// This is potentially blocking :( GameProfile profile = null;
GameProfile profile = console.getProfileCache().get(name).orElse(null); // Only fetch an online UUID in online mode
if (getOnlineMode()) {
// This is potentially blocking :(
profile = console.getProfileCache().get(name).orElse(null);
}
if (profile == null) { if (profile == null) {
// Make an OfflinePlayer using an offline mode UUID since the name has no profile // Make an OfflinePlayer using an offline mode UUID since the name has no profile
result = getOfflinePlayer(new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name)); result = getOfflinePlayer(new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name));