MCPcopy Create free account
hub / github.com/boxbeam/RedLib / asyncInit

Method asyncInit

src/redempt/redlib/misc/UserCache.java:31–49  ·  view source on GitHub ↗

Initializes the user cache asynchronously @param onComplete A Runnable to be run when the initialization is complete

(Runnable onComplete)

Source from the content-addressed store, hash-verified

29 * @param onComplete A Runnable to be run when the initialization is complete
30 */
31 public static synchronized void asyncInit(Runnable onComplete) {
32 if (initTask != null || nameCache != null) {
33 onComplete.run();
34 return;
35 }
36 initTask = CompletableFuture.runAsync(() -> {
37 if (nameCache != null) {
38 return;
39 }
40 nameCache = new ConcurrentHashMap<>();
41 for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
42 nameCache.put(player.getName().toLowerCase(Locale.ROOT), player);
43 }
44 Task.syncDelayed(() -> new EventListener<>(RedLib.getInstance(), PlayerJoinEvent.class, EventPriority.LOWEST, e -> {
45 Player player = e.getPlayer();
46 nameCache.put(player.getName().toLowerCase(Locale.ROOT), player);
47 }));
48 });
49 }
50
51 /**
52 * Initializes the user cache asynchronously

Callers 1

initMethod · 0.95

Calls 4

syncDelayedMethod · 0.95
getInstanceMethod · 0.95
getNameMethod · 0.45
getPlayerMethod · 0.45

Tested by

no test coverage detected