Search in sources :

Example 6 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class MessageUpdater method createConfigurationData.

/**
 * Constructs the {@link ConfigurationData} for exporting a messages file in its entirety.
 *
 * @return the configuration data to export with
 */
public static MessageKeyConfigurationData createConfigurationData() {
    Map<String, String> comments = ImmutableMap.<String, String>builder().put("registration", "Registration").put("password", "Password errors on registration").put("login", "Login").put("error", "Errors").put("antibot", "AntiBot").put("unregister", "Unregister").put("misc", "Other messages").put("session", "Session messages").put("on_join_validation", "Error messages when joining").put("email", "Email").put("recovery", "Password recovery by email").put("captcha", "Captcha").put("verification", "Verification code").put("time", "Time units").put("two_factor", "Two-factor authentication").build();
    Set<String> addedKeys = new HashSet<>();
    MessageKeyPropertyListBuilder builder = new MessageKeyPropertyListBuilder();
    // Add one key per section based on the comments map above so that the order is clear
    for (String path : comments.keySet()) {
        MessageKey key = Arrays.stream(MessageKey.values()).filter(p -> p.getKey().startsWith(path + ".")).findFirst().orElseThrow(() -> new IllegalStateException(path));
        builder.addMessageKey(key);
        addedKeys.add(key.getKey());
    }
    // Add all remaining keys to the property list builder
    Arrays.stream(MessageKey.values()).filter(key -> !addedKeys.contains(key.getKey())).forEach(builder::addMessageKey);
    // Create ConfigurationData instance
    Map<String, List<String>> commentsMap = comments.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> singletonList(e.getValue())));
    return new MessageKeyConfigurationData(builder, commentsMap);
}
Also used : ConsoleLoggerFactory(fr.xephi.authme.output.ConsoleLoggerFactory) Arrays(java.util.Arrays) ConvertErrorRecorder(ch.jalu.configme.properties.convertresult.ConvertErrorRecorder) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyReader(ch.jalu.configme.resource.PropertyReader) Set(java.util.Set) IOException(java.io.IOException) MessageKey(fr.xephi.authme.message.MessageKey) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) List(java.util.List) FileUtils(fr.xephi.authme.util.FileUtils) Property(ch.jalu.configme.properties.Property) Files(com.google.common.io.Files) Map(java.util.Map) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) PropertyListBuilder(ch.jalu.configme.configurationdata.PropertyListBuilder) PropertyResource(ch.jalu.configme.resource.PropertyResource) StringProperty(ch.jalu.configme.properties.StringProperty) ConsoleLogger(fr.xephi.authme.ConsoleLogger) MessageKey(fr.xephi.authme.message.MessageKey) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) HashSet(java.util.HashSet)

Example 7 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class CheckMessageKeyUsages method findUnusedKeys.

private List<MessageKey> findUnusedKeys() {
    List<MessageKey> keys = new ArrayList<>(asList(MessageKey.values()));
    File sourceFolder = new File(ToolsConstants.MAIN_SOURCE_ROOT);
    Consumer<File> fileProcessor = file -> {
        String source = FileIoUtils.readFromFile(file.toPath());
        keys.removeIf(key -> source.contains("MessageKey." + key.name()));
    };
    walkJavaFileTree(sourceFolder, fileProcessor);
    return keys;
}
Also used : Consumer(java.util.function.Consumer) List(java.util.List) Lists(com.google.common.collect.Lists) AutoToolTask(tools.utils.AutoToolTask) Predicate(java.util.function.Predicate) Arrays.asList(java.util.Arrays.asList) ToolsConstants(tools.utils.ToolsConstants) MessageKey(fr.xephi.authme.message.MessageKey) FileIoUtils(tools.utils.FileIoUtils) File(java.io.File) ArrayList(java.util.ArrayList) MessageKey(fr.xephi.authme.message.MessageKey) ArrayList(java.util.ArrayList) File(java.io.File)

Example 8 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class TranslationsGatherer method processMessagesFile.

private void processMessagesFile(String code, File file) {
    PropertyReader reader = new YamlFileReader(file);
    int availableMessages = 0;
    for (MessageKey key : MessageKey.values()) {
        if (reader.contains(key.getKey())) {
            ++availableMessages;
        }
    }
    translationInfo.add(new TranslationInfo(code, (double) availableMessages / MessageKey.values().length));
}
Also used : YamlFileReader(ch.jalu.configme.resource.YamlFileReader) MessageKey(fr.xephi.authme.message.MessageKey) PropertyReader(ch.jalu.configme.resource.PropertyReader)

Example 9 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class AddJavaDocToMessageEnumTask method executeDefault.

@Override
public void executeDefault() {
    configuration = YamlConfiguration.loadConfiguration(new File(MESSAGES_FILE));
    List<String> entries = new ArrayList<>();
    for (MessageKey entry : MessageKey.values()) {
        String tags = entry.getTags().length == 0 ? "" : ", \"" + String.join("\", \"", entry.getTags()) + "\"";
        entries.add("/** " + getMessageForJavaDoc(entry) + " */" + "\n\t" + entry.name() + "(\"" + entry.getKey() + "\"" + tags + ")");
    }
    System.out.println("\t" + String.join(",\n\n\t", entries) + ";");
}
Also used : MessageKey(fr.xephi.authme.message.MessageKey) ArrayList(java.util.ArrayList) File(java.io.File)

Example 10 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class MessageFileElementMerger method getEntryForDefaultMessageEntry.

private MessageFileElement getEntryForDefaultMessageEntry(MessageFileEntry entry) {
    MessageKey messageKey = entry.getMessageKey();
    if (messageKey == null) {
        throw new IllegalStateException("Default message file should not have unknown entries, but " + " entry with lines '" + entry.getLines() + "' has message key = null");
    }
    MessageFileEntry localEntry = entries.get(messageKey);
    if (localEntry == null) {
        return entry.convertToMissingEntryComment();
    }
    Collection<String> absentTags = missingTags.get(messageKey);
    return absentTags == null ? localEntry : localEntry.convertToEntryWithMissingTagsComment(absentTags);
}
Also used : MessageKey(fr.xephi.authme.message.MessageKey)

Aggregations

MessageKey (fr.xephi.authme.message.MessageKey)14 File (java.io.File)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 List (java.util.List)3 PropertyReader (ch.jalu.configme.resource.PropertyReader)2 Lists (com.google.common.collect.Lists)2 MessageTask (fr.xephi.authme.task.MessageTask)2 Arrays.asList (java.util.Arrays.asList)2 Consumer (java.util.function.Consumer)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 CommandSender (org.bukkit.command.CommandSender)2 Player (org.bukkit.entity.Player)2 FileIoUtils (tools.utils.FileIoUtils)2 ToolsConstants (tools.utils.ToolsConstants)2 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)1 PropertyListBuilder (ch.jalu.configme.configurationdata.PropertyListBuilder)1 Property (ch.jalu.configme.properties.Property)1 StringProperty (ch.jalu.configme.properties.StringProperty)1