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

View File

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

View File

@ -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"