Implemented Addons reloading

Relates (a bit) to #370
This commit is contained in:
Florian CUNY 2019-01-02 17:49:37 +01:00
parent c7a85c2b5a
commit be91e137a8
3 changed files with 25 additions and 15 deletions

View File

@ -7,7 +7,7 @@ import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
/** /**
* Displays information about Gamemodes, Addons and versioning. * Reloads addons and localization.
* *
* @author tastybento * @author tastybento
*/ */
@ -29,17 +29,15 @@ public class BentoBoxReloadCommand extends ConfirmableCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
this.askConfirmation(user, () -> reloadLocales(user)); this.askConfirmation(user, () -> {
return false; // Reload addons
} getPlugin().getAddonsManager().reloadAddons();
user.sendMessage("commands.bentobox.reload.addons-reloaded");
/** // Reload locales
* Reloads the languages
* @param user
*/
public void reloadLocales(User user) {
getPlugin().getLocalesManager().reloadLanguages(); getPlugin().getLocalesManager().reloadLanguages();
user.sendMessage("commands.bentobox.reload.locales-reloaded"); user.sendMessage("commands.bentobox.reload.locales-reloaded");
});
return false;
} }
} }

View File

@ -44,8 +44,6 @@ public class AddonsManager {
loaders = new HashMap<>(); loaders = new HashMap<>();
} }
//TODO: add addon reload
/** /**
* Loads all the addons from the addons folder * Loads all the addons from the addons folder
*/ */
@ -95,6 +93,20 @@ public class AddonsManager {
} }
} }
/**
* 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 * Gets the addon by name
* @param name - addon name * @param name - addon name
@ -260,5 +272,4 @@ public class AddonsManager {
addons.addAll(sortedAddons.values()); addons.addAll(sortedAddons.values());
} }
} }

View File

@ -216,6 +216,7 @@ commands:
reload: reload:
description: "reloads all locale files" description: "reloads all locale files"
locales-reloaded: "&2Languages reloaded" locales-reloaded: "&2Languages reloaded"
addons-reloaded: "&2Addons reloaded"
version: version:
plugin-version: "&2Bentobox version: &3[name]" plugin-version: "&2Bentobox version: &3[name]"
description: "display info" description: "display info"