@@ -84,24 +84,34 @@ private void migrateRemoveOldConfigSerializable() {
8484 Path oldWorldConfig = worldConfigFile .toPath ().getParent ().resolve (CONFIG_FILENAME + ".old" );
8585 Files .copy (worldConfigFile .toPath (), oldWorldConfig , COPY_ATTRIBUTES );
8686
87- return configData .replace ("==: MVWorld" , "" )
87+ return configData .replace ("==: MVWorld" , "w@: world " )
8888 .replace ("==: MVSpawnSettings" , "" )
8989 .replace ("==: MVSpawnSubSettings" , "" )
9090 .replace ("==: MVEntryFee" , "" );
9191 })
9292 .andThenTry (configData -> Files .writeString (worldConfigFile .toPath (), configData ))
9393 .andThenTry (() -> {
9494 YamlConfiguration config = YamlConfiguration .loadConfiguration (worldConfigFile );
95- List <ConfigurationSection > worlds = config .getConfigurationSection ("worlds" )
96- .getKeys (false )
97- .stream ()
98- .map (worldName -> config .getConfigurationSection ("worlds." + worldName ))
99- .toList ();
95+
96+ ConfigurationSection worldsSection = config .getConfigurationSection ("worlds" );
97+ if (worldsSection == null ) {
98+ worldsSection = config .createSection ("worlds" );
99+ }
100+
101+ List <String > worldNames = getOldConfigWorldNames (worldsSection );
102+
103+ Map <String , ConfigurationSection > worldConfigMap = new HashMap <>();
104+ for (String worldName : worldNames ) {
105+ ConfigurationSection worldSection = worldsSection .getConfigurationSection (worldName );
106+ if (worldSection != null ) {
107+ worldConfigMap .put (worldName , worldSection );
108+ }
109+ }
100110
101111 config .set ("worlds" , null );
102112
103- for (ConfigurationSection world : worlds ) {
104- config .createSection ( world . getName (), world . getValues ( true ));
113+ for (Map . Entry < String , ConfigurationSection > entry : worldConfigMap . entrySet () ) {
114+ config .set ( encodeWorldName ( entry . getKey ()), entry . getValue ( ));
105115 }
106116 config .save (worldConfigFile );
107117 })
@@ -115,6 +125,35 @@ private void migrateRemoveOldConfigSerializable() {
115125 });
116126 }
117127
128+ private @ NotNull List <String > getOldConfigWorldNames (ConfigurationSection worldsSection ) {
129+ List <String > worldNames = new ArrayList <>();
130+ recursiveGetOldConfigWorldNames (worldsSection , worldNames );
131+ return worldNames ;
132+ }
133+
134+ private void recursiveGetOldConfigWorldNames (ConfigurationSection section , List <String > worldNames ) {
135+ Set <String > keys = section .getKeys (false );
136+ if (keys .isEmpty ()) {
137+ // No keys in this section, nothing to do
138+ return ;
139+ }
140+
141+ if (keys .contains ("w@" )) {
142+ // this is the world data section already, get path without the "worlds." prefix
143+ worldNames .add (section .getCurrentPath ().substring (7 ));
144+ return ;
145+ }
146+
147+ for (String key : keys ) {
148+ ConfigurationSection dataSection = section .getConfigurationSection (key );
149+ if (dataSection == null ) {
150+ // Something is wrong with the config, skip this key
151+ continue ;
152+ }
153+ recursiveGetOldConfigWorldNames (dataSection , worldNames );
154+ }
155+ }
156+
118157 /**
119158 * Parses the worlds.yml file and creates a WorldConfig for each world in the file if it doesn't already exist.
120159 *
0 commit comments