From 0781bc16d12a4628b8429dc517f27dd3a0ceab17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sun, 1 Nov 2015 17:12:50 +0100 Subject: [PATCH] Implemented reload command --- .../xephi/authme/command/CommandManager.java | 13 ++--- .../command/executable/ReloadCommand.java | 55 +++++++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/command/executable/ReloadCommand.java diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index c735f400..12bb42d2 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -121,7 +121,7 @@ public class CommandManager { "List Dungeon Mazes", "Lists the available Dungeon Maze worlds and shows some additional information.", dungeonMazeCommand); - listWorldCommand.setCommandPermissions("dungeonmaze.command.listworlds", CommandPermissions.DefaultPermission.OP_ONLY); + listWorldCommand.setCommandPermissions("dungeonmaze.command.listworlds", CommandPermissions.DefaultPermission.OP_ONLY);*/ // Register the reload command CommandDescription reloadCommand = new CommandDescription( @@ -131,13 +131,12 @@ public class CommandManager { add("rld"); add("r"); }}, - "Reload Dungeon Maze", - "Reload the Dungeon Maze plugin.", - dungeonMazeCommand); - reloadCommand.setCommandPermissions("dungeonmaze.command.reload", CommandPermissions.DefaultPermission.OP_ONLY); - reloadCommand.addArgument(new CommandArgumentDescription("force", "True or False to force reload.", true)); + "Reload AuthMeReloaded", + "Reload the AuthMeReloaded plugin.", + authMeCommand); + reloadCommand.setCommandPermissions("authme.admin.reload", CommandPermissions.DefaultPermission.OP_ONLY); - // Register the reload permissions command + /* // Register the reload permissions command CommandDescription reloadPermissionsCommand = new CommandDescription( new ReloadPermissionsCommand(), new ArrayList() {{ diff --git a/src/main/java/fr/xephi/authme/command/executable/ReloadCommand.java b/src/main/java/fr/xephi/authme/command/executable/ReloadCommand.java new file mode 100644 index 00000000..da0e6dfa --- /dev/null +++ b/src/main/java/fr/xephi/authme/command/executable/ReloadCommand.java @@ -0,0 +1,55 @@ +package fr.xephi.authme.command.executable; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.command.CommandParts; +import fr.xephi.authme.command.ExecutableCommand; + +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.util.Profiler; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +public class ReloadCommand extends ExecutableCommand { + + /** AuthMe plugin instance. */ + private AuthMe plugin = AuthMe.getInstance(); + /** Messages instance. */ + private Messages m = Messages.getInstance(); + + /** + * Execute the command. + * + * @param sender The command sender. + * @param commandReference The command reference. + * @param commandArguments The command arguments. + * + * @return True if the command was executed successfully, false otherwise. + */ + @Override + public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { + // Profile the reload process + Profiler p = new Profiler(true); + + // Show a status message + sender.sendMessage(ChatColor.YELLOW + "Reloading Dungeon Maze..."); + + try { + Settings.reload(); + plugin.getModuleManager().reloadModules(); + m.reloadMessages(); + plugin.setupDatabase(); + } catch (Exception e) { + ConsoleLogger.showError("Fatal error occurred! Authme instance ABORTED!"); + ConsoleLogger.writeStackTrace(e); + plugin.stopOrUnload(); + return false; + } + m.send(sender, "reload"); + + // Dungeon Maze reloaded, show a status message + sender.sendMessage(ChatColor.GREEN + "Dungeon Maze has been reloaded successfully, took " + p.getTimeFormatted() + "!"); + return true; + } +}