aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0187-getPlayerUniqueId-API.patch
blob: 6ce4f8af9853b4f18a301a7e7851de8a338c1332 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 22 Mar 2018 01:40:24 -0400
Subject: [PATCH] getPlayerUniqueId API

Gets the unique ID of the player currently known as the specified player name
In Offline Mode, will return an Offline UUID

This is a more performant way to obtain a UUID for a name than loading an OfflinePlayer

diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 435a68e6c99bffdc8d6ded9deda68d4e970a2d49..d10da7acb03a2e4a67cee41a6f6fc6357eb8efd6 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1668,6 +1668,25 @@ public final class CraftServer implements Server {
         return recipients.size();
     }
 
+    // Paper start
+    @Nullable
+    public UUID getPlayerUniqueId(String name) {
+        Player player = Bukkit.getPlayerExact(name);
+        if (player != null) {
+            return player.getUniqueId();
+        }
+        GameProfile profile;
+        // Only fetch an online UUID in online mode
+        if (com.destroystokyo.paper.PaperConfig.isProxyOnlineMode()) {
+            profile = console.getProfileCache().get(name).orElse(null);
+        } else {
+            // Make an OfflinePlayer using an offline mode UUID since the name has no profile
+            profile = new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name);
+        }
+        return profile != null ? profile.getId() : null;
+    }
+    // Paper end
+
     @Override
     @Deprecated
     public OfflinePlayer getOfflinePlayer(String name) {