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 a4f58baf0006a8c1ea93d42810d325b4538e8cf6..102f1ac7c2fde48be4c7e582019b8601dcf361e4 100644 --- a/src/main/java/org/bukkit/Bukkit.java +++ b/src/main/java/org/bukkit/Bukkit.java @@ -1325,6 +1325,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. + *
+ * 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. + *
+ * + * @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 6025ba1676fe9c11f157cea2ca03d0fd2e96dc52..2864bf08aacedbbfdaa507838d42441b88953786 100644 --- a/src/main/java/org/bukkit/Server.java +++ b/src/main/java/org/bukkit/Server.java @@ -1117,6 +1117,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. + *+ * 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. + *
+ * + * @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.