mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Add getOfflinePlayerIfCached(String)
This commit is contained in:
parent
94d3dceaa9
commit
0e476e7c68
68
Spigot-API-Patches/Add-getOfflinePlayerIfCached-String.patch
Normal file
68
Spigot-API-Patches/Add-getOfflinePlayerIfCached-String.patch
Normal file
@ -0,0 +1,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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/Bukkit.java
|
||||
+++ b/src/main/java/org/bukkit/Bukkit.java
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -0,0 +0,0 @@ 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.
|
@ -0,0 +1,39 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: oxygencraft <21054297+oxygencraft@users.noreply.github.com>
|
||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -0,0 +0,0 @@ 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");
|
Loading…
Reference in New Issue
Block a user