-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add getOfflinePlayerIfCached(String)
- Loading branch information
1 parent
67c3069
commit 22c5009
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
Spigot-API-Patches/0231-Add-getOfflinePlayerIfCached-String.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: oxygencraft <[email protected]> | ||
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 bfe842364ee0a4bf39dacdbb6972477d57a4ef8a..464b2161f42a9a3969336820bc793274f4d6e942 100644 | ||
--- a/src/main/java/org/bukkit/Bukkit.java | ||
+++ b/src/main/java/org/bukkit/Bukkit.java | ||
@@ -919,6 +919,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 7c0a788900c93c29d14d8c45ac5ae3317cf4a94e..3e6331807f2c411cef3c2774a503f162685e8b46 100644 | ||
--- a/src/main/java/org/bukkit/Server.java | ||
+++ b/src/main/java/org/bukkit/Server.java | ||
@@ -770,6 +770,25 @@ public interface Server extends PluginMessageRecipient { | ||
@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. |
39 changes: 39 additions & 0 deletions
39
Spigot-Server-Patches/0595-Add-getOfflinePlayerIfCached-String.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: oxygencraft <[email protected]> | ||
Date: Sun, 25 Oct 2020 18:34:50 +1100 | ||
Subject: [PATCH] Add getOfflinePlayerIfCached(String) | ||
|
||
|
||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
index d8d29d14559169f5e8d8b4cf63d8b427b823eb2f..4e1b4d7cde8e0ea2d5e765dfc879db55e7bd669d 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
@@ -1584,6 +1584,28 @@ public final class CraftServer implements Server { | ||
return result; | ||
} | ||
|
||
+ // Paper start | ||
+ @Override | ||
+ @Nullable | ||
+ public OfflinePlayer getOfflinePlayerIfCached(String name) { | ||
+ Validate.notNull(name, "Name cannot be null"); | ||
+ Validate.notEmpty(name, "Name cannot be empty"); | ||
+ | ||
+ OfflinePlayer result = getPlayerExact(name); | ||
+ if (result == null) { | ||
+ GameProfile profile = console.getUserCache().getProfileIfCached(name); | ||
+ | ||
+ if (profile != null) { | ||
+ result = getOfflinePlayer(profile); | ||
+ } | ||
+ } else { | ||
+ offlinePlayers.remove(result.getUniqueId()); | ||
+ } | ||
+ | ||
+ return result; | ||
+ } | ||
+ // Paper end | ||
+ | ||
@Override | ||
public OfflinePlayer getOfflinePlayer(UUID id) { | ||
Validate.notNull(id, "UUID cannot be null"); |