#293 Add comments to help file, migrate header setting, write tests
This commit is contained in:
@@ -12,8 +12,6 @@ import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.PluginSettings.HELP_HEADER;
|
||||
|
||||
public class VersionCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
@@ -25,8 +23,7 @@ public class VersionCommand implements ExecutableCommand {
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
// Show some version info
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + commandService.getProperty(HELP_HEADER)
|
||||
+ " ABOUT ]==========");
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.getPluginName() + " ABOUT ]==========");
|
||||
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName()
|
||||
+ " v" + AuthMe.getPluginVersion() + ChatColor.GRAY + " (build: " + AuthMe.getPluginBuildNumber() + ")");
|
||||
sender.sendMessage(ChatColor.GOLD + "Developers:");
|
||||
|
||||
@@ -6,6 +6,8 @@ package fr.xephi.authme.command.help;
|
||||
*/
|
||||
public enum HelpMessage {
|
||||
|
||||
HEADER("header"),
|
||||
|
||||
OPTIONAL("optional"),
|
||||
|
||||
HAS_PERMISSION("hasPermission"),
|
||||
|
||||
@@ -6,12 +6,10 @@ import fr.xephi.authme.command.CommandArgumentDescription;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandUtils;
|
||||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.permission.DefaultPermission;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@@ -27,7 +25,7 @@ import static java.util.Collections.singletonList;
|
||||
/**
|
||||
* Help syntax generator for AuthMe commands.
|
||||
*/
|
||||
public class HelpProvider implements SettingsDependent {
|
||||
public class HelpProvider implements Reloadable {
|
||||
|
||||
// --- Bit flags ---
|
||||
/** Set to show a command overview. */
|
||||
@@ -50,15 +48,13 @@ public class HelpProvider implements SettingsDependent {
|
||||
|
||||
private final PermissionsManager permissionsManager;
|
||||
private final HelpMessagesService helpMessagesService;
|
||||
private String helpHeader;
|
||||
/** int with bit flags set corresponding to the above constants for enabled sections. */
|
||||
private Integer enabledSections;
|
||||
|
||||
@Inject
|
||||
HelpProvider(PermissionsManager permissionsManager, HelpMessagesService helpMessagesService, Settings settings) {
|
||||
HelpProvider(PermissionsManager permissionsManager, HelpMessagesService helpMessagesService) {
|
||||
this.permissionsManager = permissionsManager;
|
||||
this.helpMessagesService = helpMessagesService;
|
||||
reload(settings);
|
||||
}
|
||||
|
||||
private List<String> printHelp(CommandSender sender, FoundCommandResult result, int options) {
|
||||
@@ -72,7 +68,10 @@ public class HelpProvider implements SettingsDependent {
|
||||
// Return directly if no options are enabled so we don't include the help header
|
||||
return lines;
|
||||
}
|
||||
lines.add(ChatColor.GOLD + "==========[ " + helpHeader + " HELP ]==========");
|
||||
String header = helpMessagesService.getMessage(HelpMessage.HEADER);
|
||||
if (!header.isEmpty()) {
|
||||
lines.add(ChatColor.GOLD + header);
|
||||
}
|
||||
|
||||
CommandDescription command = helpMessagesService.buildLocalizedDescription(result.getCommandDescription());
|
||||
List<String> labels = ImmutableList.copyOf(result.getLabels());
|
||||
@@ -121,8 +120,7 @@ public class HelpProvider implements SettingsDependent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(Settings settings) {
|
||||
helpHeader = settings.getProperty(PluginSettings.HELP_HEADER);
|
||||
public void reload() {
|
||||
// We don't know about the reloading order of the classes, i.e. we cannot assume that HelpMessagesService
|
||||
// has already been reloaded. So set the enabledSections flag to null and redefine it first time needed.
|
||||
enabledSections = null;
|
||||
|
||||
@@ -7,9 +7,9 @@ public enum HelpSection {
|
||||
|
||||
COMMAND("command"),
|
||||
|
||||
SHORT_DESCRIPTION("description.short"),
|
||||
SHORT_DESCRIPTION("description"),
|
||||
|
||||
DETAILED_DESCRIPTION("description.detailed"),
|
||||
DETAILED_DESCRIPTION("detailedDescription"),
|
||||
|
||||
ARGUMENTS("arguments"),
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MessageFileHandler {
|
||||
* @param file the file to use for messages
|
||||
* @param defaultFile the default file from the JAR to use if no message is found
|
||||
*/
|
||||
MessageFileHandler(File file, String defaultFile) {
|
||||
public MessageFileHandler(File file, String defaultFile) {
|
||||
this.filename = file.getName();
|
||||
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||
this.defaultFile = defaultFile;
|
||||
|
||||
@@ -49,6 +49,7 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
| migrateJoinLeaveMessages(resource)
|
||||
| migrateForceSpawnSettings(resource)
|
||||
| changeBooleanSettingToLogLevelProperty(resource)
|
||||
| hasOldHelpHeaderProperty(resource)
|
||||
|| hasDeprecatedProperties(resource);
|
||||
}
|
||||
|
||||
@@ -154,6 +155,15 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean hasOldHelpHeaderProperty(PropertyResource resource) {
|
||||
if (resource.contains("settings.helpHeader")) {
|
||||
ConsoleLogger.warning("Help header setting is now in messages/help_xx.yml, "
|
||||
+ "please check the file to set it again");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for an old property path and moves it to a new path if present.
|
||||
*
|
||||
|
||||
@@ -9,10 +9,6 @@ import static com.github.authme.configme.properties.PropertyInitializer.newPrope
|
||||
|
||||
public class PluginSettings implements SettingsHolder {
|
||||
|
||||
@Comment("The name shown in the help messages")
|
||||
public static final Property<String> HELP_HEADER =
|
||||
newProperty("settings.helpHeader", "AuthMeReloaded");
|
||||
|
||||
@Comment({
|
||||
"Do you want to enable the session feature?",
|
||||
"If enabled, when a player authenticates successfully,",
|
||||
|
||||
Reference in New Issue
Block a user