This commit is contained in:
@@ -416,6 +416,7 @@ public class CommandInitializer {
|
||||
.labels("messages", "msg")
|
||||
.description("Add missing messages")
|
||||
.detailedDescription("Adds missing messages to the current messages file.")
|
||||
.withArgument("help", "Add 'help' to update the help messages file", true)
|
||||
.permission(AdminPermission.UPDATE_MESSAGES)
|
||||
.executableCommand(MessagesCommand.class)
|
||||
.register();
|
||||
|
||||
@@ -2,8 +2,10 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.help.HelpMessagesService;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.service.HelpTranslationGenerator;
|
||||
import fr.xephi.authme.service.MessageUpdater;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
@@ -11,6 +13,7 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -28,11 +31,33 @@ public class MessagesCommand implements ExecutableCommand {
|
||||
private File dataFolder;
|
||||
@Inject
|
||||
private Messages messages;
|
||||
@Inject
|
||||
private HelpTranslationGenerator helpTranslationGenerator;
|
||||
@Inject
|
||||
private HelpMessagesService helpMessagesService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
final String language = settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
if (!arguments.isEmpty() && "help".equalsIgnoreCase(arguments.get(0))) {
|
||||
updateHelpFile(sender);
|
||||
} else {
|
||||
updateMessagesFile(sender);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateHelpFile(CommandSender sender) {
|
||||
try {
|
||||
helpTranslationGenerator.updateHelpFile();
|
||||
sender.sendMessage("Successfully updated the help file");
|
||||
helpMessagesService.reload();
|
||||
} catch (IOException e) {
|
||||
sender.sendMessage("Could not update help file: " + e.getMessage());
|
||||
ConsoleLogger.logException("Could not update help file:", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMessagesFile(CommandSender sender) {
|
||||
final String language = settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
try {
|
||||
boolean isFileUpdated = new MessageUpdater(
|
||||
new File(dataFolder, getMessagePath(language)),
|
||||
|
||||
@@ -18,7 +18,7 @@ public enum HelpMessage {
|
||||
|
||||
RESULT("result");
|
||||
|
||||
|
||||
private static final String PREFIX = "common.";
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
@@ -27,11 +27,17 @@ public enum HelpMessage {
|
||||
* @param key the message key
|
||||
*/
|
||||
HelpMessage(String key) {
|
||||
this.key = "common." + key;
|
||||
this.key = PREFIX + key;
|
||||
}
|
||||
|
||||
/** @return the message key */
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/** @return the key without the common prefix */
|
||||
public String getEntryKey() {
|
||||
// Note ljacqu 20171008: #getKey is called more often than this method, so we optimize for the former method
|
||||
return key.substring(PREFIX.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class HelpMessagesService implements Reloadable {
|
||||
* @return the localized description
|
||||
*/
|
||||
public CommandDescription buildLocalizedDescription(CommandDescription command) {
|
||||
final String path = getCommandPath(command);
|
||||
final String path = COMMAND_PREFIX + getCommandSubPath(command);
|
||||
if (!messageFileHandler.hasSection(path)) {
|
||||
// Messages file does not have a section for this command - return the provided command
|
||||
return command;
|
||||
@@ -68,7 +68,7 @@ public class HelpMessagesService implements Reloadable {
|
||||
}
|
||||
|
||||
public String getDescription(CommandDescription command) {
|
||||
return getText(getCommandPath(command) + DESCRIPTION_SUFFIX, command::getDescription);
|
||||
return getText(COMMAND_PREFIX + getCommandSubPath(command) + DESCRIPTION_SUFFIX, command::getDescription);
|
||||
}
|
||||
|
||||
public String getMessage(HelpMessage message) {
|
||||
@@ -81,11 +81,14 @@ public class HelpMessagesService implements Reloadable {
|
||||
|
||||
public String getMessage(DefaultPermission defaultPermission) {
|
||||
// e.g. {default_permissions_path}.opOnly for DefaultPermission.OP_ONLY
|
||||
String path = DEFAULT_PERMISSIONS_PATH
|
||||
+ CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
|
||||
String path = DEFAULT_PERMISSIONS_PATH + getDefaultPermissionsSubPath(defaultPermission);
|
||||
return messageFileHandler.getMessage(path);
|
||||
}
|
||||
|
||||
public static String getDefaultPermissionsSubPath(DefaultPermission defaultPermission) {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
messageFileHandler = messageFileHandlerProvider.initializeHandler(
|
||||
@@ -99,8 +102,15 @@ public class HelpMessagesService implements Reloadable {
|
||||
: message;
|
||||
}
|
||||
|
||||
private static String getCommandPath(CommandDescription command) {
|
||||
return COMMAND_PREFIX + CommandUtils.constructParentList(command)
|
||||
/**
|
||||
* Returns the command subpath for the given command (i.e. the path to the translations for the given
|
||||
* command under "commands").
|
||||
*
|
||||
* @param command the command to process
|
||||
* @return the subpath for the command's texts
|
||||
*/
|
||||
public static String getCommandSubPath(CommandDescription command) {
|
||||
return CommandUtils.constructParentList(command)
|
||||
.stream()
|
||||
.map(cmd -> cmd.getLabels().get(0))
|
||||
.collect(Collectors.joining("."));
|
||||
|
||||
@@ -19,7 +19,7 @@ public enum HelpSection {
|
||||
|
||||
CHILDREN("children");
|
||||
|
||||
|
||||
private static final String PREFIX = "section.";
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
@@ -28,11 +28,17 @@ public enum HelpSection {
|
||||
* @param key the message key
|
||||
*/
|
||||
HelpSection(String key) {
|
||||
this.key = "section." + key;
|
||||
this.key = PREFIX + key;
|
||||
}
|
||||
|
||||
/** @return the message key */
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/** @return the key without the common prefix */
|
||||
public String getEntryKey() {
|
||||
// Note ljacqu 20171008: #getKey is called more often than this method, so we optimize for the former method
|
||||
return key.substring(PREFIX.length());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user