#1467 Implement messages file migration
- Create messages updater called when a messages YML file is loaded - Work in progress - Does not yet include changes to any message keys
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package fr.xephi.authme.message;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.message.updater.MessageUpdater;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
@@ -7,10 +10,35 @@ import javax.inject.Inject;
|
||||
*/
|
||||
public class MessagesFileHandler extends AbstractMessageFileHandler {
|
||||
|
||||
@Inject // Trigger injection in the superclass
|
||||
// TODO #1467: With the migration the messages handler has become so different that it would be worth
|
||||
// to remove the extension and extract common features into a helper class instead
|
||||
|
||||
@Inject
|
||||
private MessageUpdater messageUpdater;
|
||||
|
||||
MessagesFileHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
reloadInternal(false);
|
||||
}
|
||||
|
||||
private void reloadInternal(boolean isFromReload) {
|
||||
super.reload();
|
||||
|
||||
String language = getLanguage();
|
||||
boolean hasChange = messageUpdater.migrateAndSave(
|
||||
getUserLanguageFile(), createFilePath(language), createFilePath(DEFAULT_LANGUAGE));
|
||||
if (hasChange) {
|
||||
if (isFromReload) {
|
||||
ConsoleLogger.warning("Migration after reload attempt");
|
||||
} else {
|
||||
reloadInternal(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createFilePath(String language) {
|
||||
return "messages/messages_" + language + ".yml";
|
||||
|
||||
Reference in New Issue
Block a user