aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0216-Add-getOfflinePlayerIfCached-String.patch
blob: 402eff8c3868dfada711774979c0eec8a46d8e25 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: oxygencraft <21054297+oxygencraft@users.noreply.github.com>
Date: Sun, 25 Oct 2020 18:35:58 +1100
Subject: [PATCH] Add getOfflinePlayerIfCached(String)


diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 79db7b5c25a7c824b107a5c79f40c61983d2757c..732ed3724e784ad659cb4411dbd73b42a8330a2c 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -1373,6 +1373,27 @@ public final class Bukkit {
         return server.getOfflinePlayer(name);
     }
 
+    // Paper start
+    /**
+     * Gets the player by the given name, regardless if they are offline or
+     * online.
+     * <p>
+     * This will not make a web request to get the UUID for the given name,
+     * thus this method will not block. However this method will return
+     * {@code null} if the player is not cached.
+     * </p>
+     *
+     * @param name the name of the player to retrieve
+     * @return an offline player if cached, {@code null} otherwise
+     * @see #getOfflinePlayer(String)
+     * @see #getOfflinePlayer(java.util.UUID)
+     */
+    @Nullable
+    public static OfflinePlayer getOfflinePlayerIfCached(@NotNull String name) {
+        return server.getOfflinePlayerIfCached(name);
+    }
+    // Paper end
+
     /**
      * Gets the player by the given UUID, regardless if they are offline or
      * online.
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 8aba385b9d1a9b71c3304f1d802f18d4434f34d5..395f7910f535bfd33a5676b011ab62a53e30e140 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -1157,6 +1157,25 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
     @NotNull
     public OfflinePlayer getOfflinePlayer(@NotNull String name);
 
+    // Paper start
+    /**
+     * Gets the player by the given name, regardless if they are offline or
+     * online.
+     * <p>
+     * This will not make a web request to get the UUID for the given name,
+     * thus this method will not block. However this method will return
+     * {@code null} if the player is not cached.
+     * </p>
+     *
+     * @param name the name of the player to retrieve
+     * @return an offline player if cached, {@code null} otherwise
+     * @see #getOfflinePlayer(String)
+     * @see #getOfflinePlayer(java.util.UUID)
+     */
+    @Nullable
+    public OfflinePlayer getOfflinePlayerIfCached(@NotNull String name);
+    // Paper end
+
     /**
      * Gets the player by the given UUID, regardless if they are offline or
      * online.