File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
src/main/java/me/crafter/mc/lockettepro Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1010
1111import java .io .File ;
1212import java .io .IOException ;
13+ import java .io .InputStream ;
14+ import java .io .InputStreamReader ;
15+ import java .nio .charset .StandardCharsets ;
1316import java .util .*;
1417
1518public class Config {
@@ -278,6 +281,35 @@ public static void initAdditionalFiles() {
278281 if (!langfile .exists ()) {
279282 plugin .saveResource (filename , false );
280283 }
284+ updateMissingLanguageKeys (filename );
285+ }
286+ }
287+
288+ private static void updateMissingLanguageKeys (String filename ) {
289+ InputStream stream = plugin .getResource (filename );
290+ if (stream == null ) {
291+ return ;
292+ }
293+
294+ File file = new File (plugin .getDataFolder (), filename );
295+ try (InputStream input = stream ; InputStreamReader reader = new InputStreamReader (input , StandardCharsets .UTF_8 )) {
296+ YamlConfiguration bundled = YamlConfiguration .loadConfiguration (reader );
297+ YamlConfiguration existing = YamlConfiguration .loadConfiguration (file );
298+
299+ boolean changed = false ;
300+ for (String key : bundled .getKeys (true )) {
301+ if (bundled .isConfigurationSection (key )) continue ;
302+ if (!existing .contains (key )) {
303+ existing .set (key , bundled .get (key ));
304+ changed = true ;
305+ }
306+ }
307+
308+ if (changed ) {
309+ existing .save (file );
310+ }
311+ } catch (Exception e ) {
312+ plugin .getLogger ().warning ("Failed to update missing language keys for " + filename + ": " + e .getMessage ());
281313 }
282314 }
283315
You can’t perform that action at this time.
0 commit comments