2019-05-27 11:13:41 +02:00
|
|
|
From 272bed4023311ec64b7a6756561e374583ad49a3 Mon Sep 17 00:00:00 2001
|
2018-03-22 06:41:44 +01:00
|
|
|
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
|
2019-05-27 11:13:41 +02:00
|
|
|
index 746d2888d..ad1950980 100644
|
2018-03-22 06:41:44 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2019-05-06 05:53:47 +02:00
|
|
|
@@ -1355,6 +1355,26 @@ public final class CraftServer implements Server {
|
2018-03-22 06:41:44 +01:00
|
|
|
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
|
2019-05-06 05:53:47 +02:00
|
|
|
+ if (net.minecraft.server.MinecraftServer.getServer().getOnlineMode()
|
2018-03-22 06:41:44 +01:00
|
|
|
+ || (org.spigotmc.SpigotConfig.bungee && com.destroystokyo.paper.PaperConfig.bungeeOnlineMode)) {
|
|
|
|
+ profile = console.getUserCache().getProfile( name );
|
|
|
|
+ } 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) {
|
|
|
|
--
|
2019-03-20 02:46:00 +01:00
|
|
|
2.21.0
|
2018-03-22 06:41:44 +01:00
|
|
|
|