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);
}
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;
}
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));
}
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) + ";");
}
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);
}
Aggregations