Skip to content

Commit 0c511ff

Browse files
committed
Fix world not loading when the world name has . in it
1 parent 3356724 commit 0c511ff

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,15 @@ private void migrateRemoveOldConfigSerializable() {
121121
* @return A tuple containing a list of the new WorldConfigs added and a list of the worlds removed from the config.
122122
*/
123123
private NewAndRemovedWorlds parseNewAndRemovedWorlds() {
124-
Set<String> allWorldsInConfig = worldsConfig.getKeys(false);
124+
List<String> allWorldsInConfig = worldsConfig.getKeys(false)
125+
.stream()
126+
.map(this::decodeWorldName)
127+
.toList();
128+
125129
List<WorldConfig> newWorldsAdded = new ArrayList<>();
126130

127131
for (String worldName : allWorldsInConfig) {
132+
Logging.warning("Loading world: %s", worldName);
128133
getWorldConfig(worldName)
129134
.peek(config -> config.load(getWorldConfigSection(worldName)))
130135
.orElse(() -> {
@@ -174,7 +179,7 @@ public Try<Void> save() {
174179
worldConfig.save().onFailure(e -> {
175180
throw new RuntimeException("Failed to save world config: " + worldName, e);
176181
});
177-
worldsConfig.set(worldName, worldConfig.getConfigurationSection());
182+
worldsConfig.set(encodeWorldName(worldName), worldConfig.getConfigurationSection());
178183
});
179184
worldsConfig.save(worldConfigFile);
180185
}).onFailure(e -> {
@@ -214,7 +219,7 @@ public Try<Void> save() {
214219
*/
215220
public void deleteWorldConfig(@NotNull String worldName) {
216221
worldConfigMap.remove(worldName);
217-
worldsConfig.set(worldName, null);
222+
worldsConfig.set(encodeWorldName(worldName), null);
218223
}
219224

220225
/**
@@ -225,11 +230,23 @@ public void deleteWorldConfig(@NotNull String worldName) {
225230
* @return The {@link ConfigurationSection} for the given world.
226231
*/
227232
private ConfigurationSection getWorldConfigSection(String worldName) {
233+
worldName = encodeWorldName(worldName);
228234
return worldsConfig.isConfigurationSection(worldName)
229235
? worldsConfig.getConfigurationSection(worldName)
230236
: worldsConfig.createSection(worldName);
231237
}
232238

239+
/**
240+
* Dot is a special character in YAML that causes sub-path issues.
241+
*/
242+
private String encodeWorldName(String worldName) {
243+
return worldName.replace(".", "[dot]");
244+
}
245+
246+
private String decodeWorldName(String worldName) {
247+
return worldName.replace("[dot]", ".");
248+
}
249+
233250
private static final class ConfigMigratedException extends RuntimeException {
234251
private ConfigMigratedException() {
235252
super("Config migrated");

0 commit comments

Comments
 (0)