Skip to content

Commit

Permalink
Add loadMessages() and more changes
Browse files Browse the repository at this point in the history
- `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
  • Loading branch information
srnyx committed Dec 30, 2022
1 parent fcfa089 commit 1face9b
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions api/src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>Do not try to override this method! Override {@link #enable()} instead
Expand Down Expand Up @@ -103,26 +107,24 @@ public final void onEnable() {
*/
private void enablePlugin() {
// Check if required dependencies are installed
final Set<AnnoyingDependency> missing = options.dependencies.stream()
final String missing = options.dependencies.stream()
.filter(dependency -> dependency.required && dependency.isNotInstalled())
.collect(Collectors.toSet());
if (!missing.isEmpty()) {
final Set<String> 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;
}

// 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);
Expand Down

0 comments on commit 1face9b

Please sign in to comment.