Skip to content

Commit 37df16a

Browse files
Optimize player finder again, cache all players when it >5k
1 parent 75d113e commit 37df16a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/org/maxgamer/quickshop/util/PlayerFinder.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,24 @@ public static UUID findUUIDByName(String name) {
5050

5151
@Nullable
5252
private static OfflinePlayer findPlayerByName(String name, java.util.Collection<? extends org.bukkit.OfflinePlayer> players) {
53-
//Cache all players when offline player is too much
53+
//Cache all players when offline player is too many
5454
boolean cacheAllPlayers = players.size() > 5000;
55+
OfflinePlayer result = null;
5556
for (OfflinePlayer player : players) {
5657
String playerName = player.getName();
5758
if (playerName != null) {
5859
if (playerName.equalsIgnoreCase(name)) {
59-
return player;
60-
} else if (cacheAllPlayers) {
60+
result = player;
61+
if (!cacheAllPlayers) {
62+
return result;
63+
}
64+
}
65+
if (cacheAllPlayers) {
6166
string2UUIDCache.put(playerName.toLowerCase(Locale.ROOT), player.getUniqueId());
6267
}
6368
}
6469
}
65-
return null;
70+
return result;
6671
}
6772

6873
public static OfflinePlayer findOfflinePlayerByName(String name) {

0 commit comments

Comments
 (0)