From 84ec10106cc2a5d4aca47f8a976a457fc7a0298d Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Wed, 29 Oct 2025 19:24:40 +1100 Subject: [PATCH] lang file will no longer be modified by the plugin, instead lang file can still be recreated on plugin reload --- .../rockyhawk/commandpanels/FileHandler.java | 47 +------------------ .../formatter/language/LanguageManager.java | 12 ++--- 2 files changed, 5 insertions(+), 54 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/FileHandler.java b/src/me/rockyhawk/commandpanels/FileHandler.java index 6306da8..69afbbb 100644 --- a/src/me/rockyhawk/commandpanels/FileHandler.java +++ b/src/me/rockyhawk/commandpanels/FileHandler.java @@ -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 defaultKeys = defaultLang.getKeys(false); - Set existingKeys = existingLang.getKeys(false); - - // find missing key - Set missingKeys = new HashSet<>(defaultKeys); - missingKeys.removeAll(existingKeys); - - // find extra key - Set 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")); diff --git a/src/me/rockyhawk/commandpanels/formatter/language/LanguageManager.java b/src/me/rockyhawk/commandpanels/formatter/language/LanguageManager.java index 1c5a884..50cd842 100644 --- a/src/me/rockyhawk/commandpanels/formatter/language/LanguageManager.java +++ b/src/me/rockyhawk/commandpanels/formatter/language/LanguageManager.java @@ -24,15 +24,9 @@ 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)); + YamlConfiguration langFile = YamlConfiguration.loadConfiguration(new File(ctx.plugin.getDataFolder(), "lang.yml")); + for (String key : langFile.getKeys(false)) { + translations.put(key.toLowerCase(), langFile.getString(key)); } }