From 1face9bf59ebdcdb318d71d9d23db95b5218a2f2 Mon Sep 17 00:00:00 2001 From: srnyx <25808801+srnyx@users.noreply.github.com> Date: Fri, 30 Dec 2022 15:40:00 -0500 Subject: [PATCH] Add `loadMessages()` and more changes - `messages.yml` loading has been moved into it's own method, `AnnoyingPlugin#loadMessages()` - Removed translating some of the message options keys into their strings from `messages.yml` - Getting missing dependencies and their names improved --- .../xyz/srnyx/annoyingapi/AnnoyingPlugin.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java b/api/src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java index 707b161..dd59436 100644 --- a/api/src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java +++ b/api/src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java @@ -62,15 +62,19 @@ public AnnoyingPlugin() { */ @Override public final void onLoad() { - messages = new AnnoyingResource(this, options.messagesFileName); - options.prefix = getMessagesString(options.prefix); - options.splitterJson = getMessagesString(options.splitterJson); - options.splitterPlaceholder = getMessagesString(options.splitterPlaceholder); - + // Load messages + loadMessages(); // Custom onLoad load(); } + /** + * Loads the messages.yml file + */ + public void loadMessages() { + messages = new AnnoyingResource(this, options.messagesFileName); + } + /** * Called when the plugin is enabled. *

Do not try to override this method! Override {@link #enable()} instead @@ -103,14 +107,12 @@ public final void onEnable() { */ private void enablePlugin() { // Check if required dependencies are installed - final Set missing = options.dependencies.stream() + final String missing = options.dependencies.stream() .filter(dependency -> dependency.required && dependency.isNotInstalled()) - .collect(Collectors.toSet()); - if (!missing.isEmpty()) { - final Set missingNames = missing.stream() - .map(dependency -> dependency.name) - .collect(Collectors.toSet()); - log(Level.SEVERE, "&cDisabling " + getName() + " because it's missing required dependencies: &4" + StringUtils.join(missingNames, "&c, &4")); + .map(dependency -> dependency.name) + .collect(Collectors.joining("&c, &4")); + if (missing.length() != 0) { + log(Level.SEVERE, "&cDisabling " + getName() + " because it's missing required dependencies: &4" + missing); disablePlugin(); return; } @@ -118,11 +120,11 @@ private void enablePlugin() { // Start messages final String name = getName() + " v" + getDescription().getVersion(); final String authors = "By " + String.join(", ", getDescription().getAuthors()); - final String line = StringUtils.repeat("-", Math.max(name.length(), authors.length())); - log(Level.INFO, options.colorDark + line); + final String line = options.colorDark + StringUtils.repeat("-", Math.max(name.length(), authors.length())); + log(Level.INFO, line); log(Level.INFO, options.colorLight + name); log(Level.INFO, options.colorLight + authors); - log(Level.INFO, options.colorDark + line); + log(Level.INFO, line); // Register commands/events options.commands.forEach(AnnoyingCommand::register);