From 50cee40531abf2fc82b7a8bd8dc96b7ff2fec797 Mon Sep 17 00:00:00 2001 From: Sxtanna Date: Fri, 24 Jul 2020 19:02:17 -0400 Subject: [PATCH] updated LocalExpansionManager to accept a command sender to notify of load completion details --- .../clip/placeholderapi/PlaceholderAPIPlugin.java | 8 ++------ .../commands/impl/local/CommandReload.java | 1 - .../expansion/manager/LocalExpansionManager.java | 14 ++++++++++---- .../listeners/ServerLoadEventListener.java | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java index 12474ce..fa32fe9 100644 --- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java +++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java @@ -28,7 +28,6 @@ import me.clip.placeholderapi.expansion.manager.CloudExpansionManager; import me.clip.placeholderapi.expansion.manager.LocalExpansionManager; import me.clip.placeholderapi.listeners.ServerLoadEventListener; import me.clip.placeholderapi.updatechecker.UpdateChecker; -import me.clip.placeholderapi.util.Msg; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -128,7 +127,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin reloadConfig(); - getLocalExpansionManager().load(); + getLocalExpansionManager().load(sender); if (config.isCloudEnabled()) { @@ -138,9 +137,6 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { getCloudExpansionManager().kill(); } - - Msg.msg(sender, - getLocalExpansionManager().getIdentifiers().size() + " &aplaceholder hooks successfully registered!"); } @@ -232,7 +228,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin } catch (final ExceptionInInitializerError | ClassNotFoundException ignored) { - Bukkit.getScheduler().runTaskLater(this, getLocalExpansionManager()::load, 1); + Bukkit.getScheduler().runTaskLater(this, () -> getLocalExpansionManager().load(Bukkit.getConsoleSender()), 1); } } diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandReload.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandReload.java index 90277ea..31f4e69 100644 --- a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandReload.java +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandReload.java @@ -21,7 +21,6 @@ public final class CommandReload extends PlaceholderCommand public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) { plugin.reloadConf(sender); - Msg.msg(sender, "&fPlaceholder&7API &bconfiguration reloaded!"); } } 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 c05982a..c6ca1af 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java @@ -13,7 +13,9 @@ import me.clip.placeholderapi.expansion.Taskable; import me.clip.placeholderapi.expansion.VersionSpecific; import me.clip.placeholderapi.expansion.cloud.CloudExpansion; import me.clip.placeholderapi.util.FileUtil; +import me.clip.placeholderapi.util.Msg; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -63,9 +65,9 @@ public final class LocalExpansionManager implements Listener } } - public void load() + public void load(@NotNull final CommandSender sender) { - registerAll(); + registerAll(sender); } public void kill() @@ -266,7 +268,7 @@ public final class LocalExpansionManager implements Listener } - private void registerAll() + private void registerAll(@NotNull final CommandSender sender) { plugin.getLogger().info("Placeholder expansion registration initializing..."); @@ -277,7 +279,11 @@ public final class LocalExpansionManager implements Listener return; } - Bukkit.getScheduler().runTask(plugin, () -> classes.forEach(this::register)); + Bukkit.getScheduler().runTask(plugin, () -> { + final long registered = classes.stream().map(this::register).filter(Optional::isPresent).count(); + Msg.msg(sender, + registered == 0 ? "&6No expansions were registered!" : registered + "&a placeholder hooks successfully registered!"); + }); }); } diff --git a/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java b/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java index c916214..ae1b93d 100644 --- a/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java +++ b/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java @@ -55,7 +55,7 @@ public final class ServerLoadEventListener implements Listener public void onServerLoad(@NotNull final ServerLoadEvent event) { HandlerList.unregisterAll(this); - plugin.getLocalExpansionManager().load(); + plugin.getLocalExpansionManager().load(Bukkit.getConsoleSender()); } }