Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@
* @return A tuple containing a list of the new WorldConfigs added and a list of the worlds removed from the config.
*/
private NewAndRemovedWorlds parseNewAndRemovedWorlds() {
Set<String> allWorldsInConfig = worldsConfig.getKeys(false);
List<String> allWorldsInConfig = worldsConfig.getKeys(false)
.stream()
.map(this::decodeWorldName)
.toList();

List<WorldConfig> newWorldsAdded = new ArrayList<>();

for (String worldName : allWorldsInConfig) {
Expand Down Expand Up @@ -174,7 +178,7 @@
worldConfig.save().onFailure(e -> {
throw new RuntimeException("Failed to save world config: " + worldName, e);
});
worldsConfig.set(worldName, worldConfig.getConfigurationSection());
worldsConfig.set(encodeWorldName(worldName), worldConfig.getConfigurationSection());
});
worldsConfig.save(worldConfigFile);
}).onFailure(e -> {
Expand Down Expand Up @@ -214,7 +218,7 @@
*/
public void deleteWorldConfig(@NotNull String worldName) {
worldConfigMap.remove(worldName);
worldsConfig.set(worldName, null);
worldsConfig.set(encodeWorldName(worldName), null);
}

/**
Expand All @@ -225,11 +229,23 @@
* @return The {@link ConfigurationSection} for the given world.
*/
private ConfigurationSection getWorldConfigSection(String worldName) {
worldName = encodeWorldName(worldName);

Check warning on line 232 in src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Assignment of parameter 'worldName' is not allowed. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java:232:19: warning: Assignment of parameter 'worldName' is not allowed. (com.puppycrawl.tools.checkstyle.checks.coding.ParameterAssignmentCheck)
return worldsConfig.isConfigurationSection(worldName)
? worldsConfig.getConfigurationSection(worldName)
: worldsConfig.createSection(worldName);
}

/**
* Dot is a special character in YAML that causes sub-path issues.
*/
private String encodeWorldName(String worldName) {
return worldName.replace(".", "[dot]");

Check warning on line 242 in src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "[dot]" appears 2 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java:242:39: warning: The String "[dot]" appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)

Check warning on line 242 in src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "." appears 2 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java:242:34: warning: The String "." appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)
}

private String decodeWorldName(String worldName) {
return worldName.replace("[dot]", ".");
}

private static final class ConfigMigratedException extends RuntimeException {
private ConfigMigratedException() {
super("Config migrated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ class WorldConfigMangerTest : TestWithMockBukkit() {

@Test
fun `Add a new world to config`() {
val worldConfig = worldConfigManager.addWorldConfig("newworld")
val worldConfig = worldConfigManager.addWorldConfig("new.world")
assertNotNull(worldConfig)
assertEquals("newworld", worldConfig.worldName)
assertEquals("new.world", worldConfig.worldName)
assertTrue(worldConfigManager.save().isSuccess)
assertConfigEquals("/worlds/newworld_worlds.yml", "worlds.yml")

// Make sure the world still can be loaded after save
assertTrue(worldConfigManager.load().isSuccess)
assertEquals("new.world", worldConfigManager.getWorldConfig("new.world").orNull?.worldName)
assertConfigEquals("/worlds/newworld_worlds.yml", "worlds.yml")
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/worlds/newworld_worlds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ world_nether:
spawning: {}
world-blacklist: []
version: 1.2
newworld:
new[dot]world:
adjust-spawn: false
alias: ''
allow-advancement-grant: true
Expand Down
Loading