mirror of
https://github.com/rockyhawk64/CommandPanels.git
synced 2025-11-18 07:14:17 +01:00
lang file will no longer be modified by the plugin, instead lang file can still be recreated on plugin reload
This commit is contained in:
parent
5d9fbbbcff
commit
84ec10106c
@ -133,13 +133,9 @@ public class FileHandler {
|
||||
// if lang file is missing add it back
|
||||
private void createLangFile() {
|
||||
File messagesFile = new File(ctx.plugin.getDataFolder(), "lang.yml");
|
||||
YamlConfiguration messagesYaml = Message.toYaml();
|
||||
if (messagesFile.exists()) {
|
||||
// Update, lang file already exists
|
||||
updateLangFile(messagesFile, messagesYaml);
|
||||
return;
|
||||
}
|
||||
if (messagesFile.exists()) return;
|
||||
|
||||
YamlConfiguration messagesYaml = Message.toYaml();
|
||||
try {
|
||||
messagesYaml.save(messagesFile);
|
||||
} catch (IOException ex) {
|
||||
@ -148,45 +144,6 @@ public class FileHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLangFile(File langFile, YamlConfiguration defaultLang) {
|
||||
YamlConfiguration existingLang = YamlConfiguration.loadConfiguration(langFile);
|
||||
|
||||
boolean hasChanges = false;
|
||||
Set<String> defaultKeys = defaultLang.getKeys(false);
|
||||
Set<String> existingKeys = existingLang.getKeys(false);
|
||||
|
||||
// find missing key
|
||||
Set<String> missingKeys = new HashSet<>(defaultKeys);
|
||||
missingKeys.removeAll(existingKeys);
|
||||
|
||||
// find extra key
|
||||
Set<String> extraKeys = new HashSet<>(existingKeys);
|
||||
extraKeys.removeAll(defaultKeys);
|
||||
|
||||
// add missing key
|
||||
for (String missingKey : missingKeys) {
|
||||
String defaultValue = defaultLang.getString(missingKey);
|
||||
existingLang.set(missingKey, defaultValue);
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
// remove extra key
|
||||
for (String extraKey : extraKeys) {
|
||||
existingLang.set(extraKey, null);
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
// If file changes, save it
|
||||
if (hasChanges) {
|
||||
try {
|
||||
existingLang.save(langFile);
|
||||
} catch (IOException e) {
|
||||
Bukkit.getGlobalRegionScheduler().run(ctx.plugin, task ->
|
||||
ctx.text.sendError(ctx.plugin.getServer().getConsoleSender(), Message.FILE_UPDATE_LANG_FAIL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConfigFiles() {
|
||||
// Register config files
|
||||
config = YamlConfiguration.loadConfiguration(new File(ctx.plugin.getDataFolder(), "config.yml"));
|
||||
|
||||
@ -24,16 +24,10 @@ public class LanguageManager {
|
||||
// The plugin will ensure they are still detected without it
|
||||
public void reloadTranslations() {
|
||||
translations.clear();
|
||||
try {
|
||||
YamlConfiguration langFile = YamlConfiguration.loadConfiguration(new File(ctx.plugin.getDataFolder(), "lang.yml"));
|
||||
for (String key : langFile.getKeys(false)) {
|
||||
translations.put(key.toLowerCase(), langFile.getString(key));
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Send raw message as text class will not be initialised here
|
||||
Bukkit.getConsoleSender().sendMessage(Component.text(
|
||||
"[CommandPanels] Language file could not be loaded, periods should not be in language keys.", NamedTextColor.RED));
|
||||
}
|
||||
}
|
||||
|
||||
public String translate(Message message, Object... args) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user