#704 Implement reloading via injector

- Create interfaces Reloadable and SettingsDependent to recognize reloadable classes
- Iterate through instances in injector to reload
This commit is contained in:
ljacqu
2016-05-12 19:51:10 +02:00
parent 4bad04b160
commit e04f7dc711
19 changed files with 240 additions and 50 deletions
@@ -4,7 +4,11 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.initialization.AuthMeServiceInitializer;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;
@@ -18,10 +22,25 @@ public class ReloadCommand implements ExecutableCommand {
@Inject
private AuthMe plugin;
@Inject
private AuthMeServiceInitializer initializer;
@Inject
private NewSetting settings;
@Inject
private DataSource dataSource;
@Override
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
try {
plugin.reload();
settings.reload();
// We do not change database type for consistency issues, but we'll output a note in the logs
if (!settings.getProperty(DatabaseSettings.BACKEND).equals(dataSource.getType())) {
ConsoleLogger.info("Note: cannot change database type during /authme reload");
sender.sendMessage("Note: cannot change database type during /authme reload");
}
initializer.performReloadOnServices();
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
} catch (Exception e) {
sender.sendMessage("Error occurred during reload of AuthMe: aborting");
@@ -7,6 +7,7 @@ import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.command.CommandPermissions;
import fr.xephi.authme.command.CommandUtils;
import fr.xephi.authme.command.FoundCommandResult;
import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsManager;
@@ -26,7 +27,7 @@ import static java.util.Collections.singletonList;
/**
* Help syntax generator for AuthMe commands.
*/
public class HelpProvider {
public class HelpProvider implements SettingsDependent {
// --- Bit flags ---
/** Set to <i>not</i> show the command. */
@@ -46,12 +47,12 @@ public class HelpProvider {
public static final int ALL_OPTIONS = ~HIDE_COMMAND;
private final PermissionsManager permissionsManager;
private final String helpHeader;
private String helpHeader;
@Inject
public HelpProvider(PermissionsManager permissionsManager, NewSetting settings) {
this.permissionsManager = permissionsManager;
this.helpHeader = settings.getProperty(PluginSettings.HELP_HEADER);
loadSettings(settings);
}
public List<String> printHelp(CommandSender sender, FoundCommandResult result, int options) {
@@ -88,6 +89,11 @@ public class HelpProvider {
return lines;
}
@Override
public void loadSettings(NewSetting settings) {
helpHeader = settings.getProperty(PluginSettings.HELP_HEADER);
}
private static void printDetailedDescription(CommandDescription command, List<String> lines) {
lines.add(ChatColor.GOLD + "Short description: " + ChatColor.WHITE + command.getDescription());
lines.add(ChatColor.GOLD + "Detailed description:");