From c9cf609b9194c373466abd635a01ff4ea08bef1b Mon Sep 17 00:00:00 2001 From: wxipwastaken Date: Mon, 18 Jul 2022 17:02:58 +0300 Subject: [PATCH] Added a 1 second delay to fix a mysterious bug that didn't allow expansions to load --- .../manager/LocalExpansionManager.java | 78 ++++++++++--------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java b/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java index 8f11d3f..29365a4 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java @@ -61,6 +61,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -336,43 +337,48 @@ public final class LocalExpansionManager implements Listener { private void registerAll(@NotNull final CommandSender sender) { Msg.info("Placeholder expansion registration initializing..."); - Futures.onMainThread(plugin, findExpansionsOnDisk(), (classes, exception) -> { - if (exception != null) { - Msg.severe("Failed to load class files of expansion.", exception); - return; + new BukkitRunnable() { + @Override + public void run() { + Futures.onMainThread(plugin, findExpansionsOnDisk(), (classes, exception) -> { + if (exception != null) { + Msg.severe("Failed to load class files of expansion.", exception); + return; + } + + final List registered = classes.stream() + .filter(Objects::nonNull) + .map(LocalExpansionManager.this::register) + .filter(Optional::isPresent) + .map(Optional::get) + .collect(Collectors.toList()); + + final long needsUpdate = registered.stream() + .map(expansion -> plugin.getCloudExpansionManager().findCloudExpansionByName(expansion.getName()).orElse(null)) + .filter(Objects::nonNull) + .filter(CloudExpansion::shouldUpdate) + .count(); + + StringBuilder message = new StringBuilder(registered.size() == 0 ? "&6" : "&a") + .append(registered.size()) + .append(' ') + .append("placeholder hook(s) registered!"); + + if (needsUpdate > 0) { + message.append(' ') + .append("&6") + .append(needsUpdate) + .append(' ') + .append("placeholder hook(s) have an update available."); + } + + + Msg.msg(sender, message.toString()); + + Bukkit.getPluginManager().callEvent(new ExpansionsLoadedEvent(registered)); + }); } - - final List registered = classes.stream() - .filter(Objects::nonNull) - .map(this::register) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList()); - - final long needsUpdate = registered.stream() - .map(expansion -> plugin.getCloudExpansionManager().findCloudExpansionByName(expansion.getName()).orElse(null)) - .filter(Objects::nonNull) - .filter(CloudExpansion::shouldUpdate) - .count(); - - StringBuilder message = new StringBuilder(registered.size() == 0 ? "&6" : "&a") - .append(registered.size()) - .append(' ') - .append("placeholder hook(s) registered!"); - - if (needsUpdate > 0) { - message.append(' ') - .append("&6") - .append(needsUpdate) - .append(' ') - .append("placeholder hook(s) have an update available."); - } - - - Msg.msg(sender, message.toString()); - - Bukkit.getPluginManager().callEvent(new ExpansionsLoadedEvent(registered)); - }); + }.runTaskLater(plugin, 20L); } private void unregisterAll() {