File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
src/main/java/org/maxgamer/quickshop/util Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 3939 */
4040public final class PlayerFinder {
4141
42- private static final Cache <String , UUID > string2UUIDCache = CacheBuilder .newBuilder ().expireAfterAccess (30 , TimeUnit .MINUTES ).build ();
42+ private static final Cache <String , UUID > string2UUIDCache = CacheBuilder .newBuilder ().expireAfterAccess (60 , TimeUnit .MINUTES ).build ();
4343
4444 private PlayerFinder () {
4545 }
@@ -49,11 +49,17 @@ public static UUID findUUIDByName(String name) {
4949 }
5050
5151 @ Nullable
52- private static OfflinePlayer findPlayerByName (String name , Iterable <? extends OfflinePlayer > players ) {
52+ private static OfflinePlayer findPlayerByName (String name , java .util .Collection <? extends org .bukkit .OfflinePlayer > players ) {
53+ //Cache all players when offline player is too much
54+ boolean cacheAllPlayers = players .size () > 5000 ;
5355 for (OfflinePlayer player : players ) {
5456 String playerName = player .getName ();
55- if (playerName != null && playerName .equalsIgnoreCase (name )) {
56- return player ;
57+ if (playerName != null ) {
58+ if (playerName .equalsIgnoreCase (name )) {
59+ return player ;
60+ } else if (cacheAllPlayers ) {
61+ string2UUIDCache .put (playerName .toLowerCase (Locale .ROOT ), player .getUniqueId ());
62+ }
5763 }
5864 }
5965 return null ;
You can’t perform that action at this time.
0 commit comments