Skip to content

Commit 5367928

Browse files
committed
Remove unneeded db lookup for tabcomplete on startup
1 parent 9fda1cd commit 5367928

2 files changed

Lines changed: 18 additions & 25 deletions

File tree

AdvancedCore/src/main/java/com/bencodez/advancedcore/AdvancedCorePlugin.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -577,31 +577,8 @@ public void loadTabComplete() {
577577
public void reload() {
578578
ArrayList<String> players = new ArrayList<>();
579579

580-
// Prefer UUIDs from storage; names come from UuidLookup cache (seeded at
581-
// startup)
582-
for (String uuid : getUserManager().getAllUUIDs()) {
583-
String name = UuidLookup.getInstance().getCachedName(uuid);
584-
if (name == null || name.isEmpty()) {
585-
// Fallback: try to read from user data without DB lookup
586-
try {
587-
AdvancedCoreUser user = getUserManager().getUser(UUID.fromString(uuid), false);
588-
if (user != null) {
589-
String stored = user.getData().getString("PlayerName", UserDataFetchMode.NO_DB_LOOKUP);
590-
if (stored != null && !stored.isEmpty()
591-
&& !stored.equalsIgnoreCase("Error getting name")
592-
&& !stored.equalsIgnoreCase("null")) {
593-
UuidLookup.getInstance().cacheMapping(uuid, stored);
594-
name = stored;
595-
}
596-
}
597-
} catch (Exception ignored) {
598-
}
599-
}
600-
601-
if (name != null && !name.isEmpty() && !players.contains(name)) {
602-
players.add(name);
603-
}
604-
}
580+
// fetch all cached names; this avoids hitting the DB
581+
players.addAll(UuidLookup.getInstance().getAllCachedNames());
605582

606583
// Always include currently online players
607584
for (Player p : Bukkit.getOnlinePlayers()) {
@@ -615,6 +592,7 @@ public void reload() {
615592

616593
@Override
617594
public void updateReplacements() {
595+
// ensure new online players are added to the replacement list
618596
for (Player player : Bukkit.getOnlinePlayers()) {
619597
if (!getReplace().contains(player.getName())) {
620598
getReplace().add(player.getName());

AdvancedCore/src/main/java/com/bencodez/advancedcore/api/player/UuidLookup.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.bencodez.advancedcore.api.player;
22

33
import java.nio.charset.StandardCharsets;
4+
import java.util.ArrayList;
5+
import java.util.List;
46
import java.util.Locale;
57
import java.util.UUID;
68
import java.util.concurrent.ConcurrentHashMap;
@@ -31,6 +33,19 @@ public static UuidLookup getInstance() {
3133
private UuidLookup() {
3234
// Cache is owned here.
3335
}
36+
37+
/**
38+
* Retrieve all player names currently cached in memory.
39+
*
40+
* <p>This returns a snapshot of the internal uuid→name map values. It does not
41+
* hit any storage, so it’s safe to call from tab‑complete code.</p>
42+
*
43+
* @return list containing all cached player names (may include duplicates)
44+
*/
45+
public List<String> getAllCachedNames() {
46+
return new ArrayList<>(uuidToName.values());
47+
}
48+
3449

3550
/*
3651
* ========================= Public API =========================

0 commit comments

Comments
 (0)