Skip to content

Commit

Permalink
Implemented Addons reloading
Browse files Browse the repository at this point in the history
Relates (a bit) to #370
  • Loading branch information
Poslovitch committed Jan 2, 2019
1 parent c7a85c2 commit be91e13
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import world.bentobox.bentobox.api.user.User;

/**
* Displays information about Gamemodes, Addons and versioning.
* Reloads addons and localization.
*
* @author tastybento
*/
Expand All @@ -29,17 +29,15 @@ public void setup() {

@Override
public boolean execute(User user, String label, List<String> args) {
this.askConfirmation(user, () -> reloadLocales(user));
this.askConfirmation(user, () -> {
// Reload addons
getPlugin().getAddonsManager().reloadAddons();
user.sendMessage("commands.bentobox.reload.addons-reloaded");

// Reload locales
getPlugin().getLocalesManager().reloadLanguages();
user.sendMessage("commands.bentobox.reload.locales-reloaded");
});
return false;
}

/**
* Reloads the languages
* @param user
*/
public void reloadLocales(User user) {
getPlugin().getLocalesManager().reloadLanguages();
user.sendMessage("commands.bentobox.reload.locales-reloaded");
}

}
17 changes: 14 additions & 3 deletions src/main/java/world/bentobox/bentobox/managers/AddonsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public AddonsManager(BentoBox plugin) {
loaders = new HashMap<>();
}

//TODO: add addon reload

/**
* Loads all the addons from the addons folder
*/
Expand Down Expand Up @@ -95,6 +93,20 @@ public void enableAddons() {
}
}

/**
* Reloads all the enabled addons
*/
public void reloadAddons() {
if (!addons.isEmpty()) {
plugin.log("Reloading addons...");
addons.stream().filter(Addon::isEnabled).forEach(addon -> {
plugin.log("Reloading " + addon.getDescription().getName() + "...");
addon.onReload();
});
plugin.log("Addons successfully reloaded.");
}
}

/**
* Gets the addon by name
* @param name - addon name
Expand Down Expand Up @@ -260,5 +272,4 @@ private void sortAddons() {
addons.addAll(sortedAddons.values());
}


}
1 change: 1 addition & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ commands:
reload:
description: "reloads all locale files"
locales-reloaded: "&2Languages reloaded"
addons-reloaded: "&2Addons reloaded"
version:
plugin-version: "&2Bentobox version: &3[name]"
description: "display info"
Expand Down

0 comments on commit be91e13

Please sign in to comment.