Add getWorldConfig method

This commit is contained in:
Ben Woo 2023-09-01 11:20:25 +08:00
parent 42eadd91a5
commit 6effeacd1b
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
4 changed files with 9 additions and 7 deletions

View File

@ -29,15 +29,13 @@ public class WorldManager {
}
public void addWorld(String worldName) {
ConfigurationSection worldConfigSection = worldsConfigFile.getWorldConfigSection(worldName);
WorldConfig worldConfig = new WorldConfig(worldConfigSection);
WorldConfig worldConfig = worldsConfigFile.getWorldConfig(worldName);
//todo
saveWorldsConfig();
}
public void loadWorld(String worldName) {
ConfigurationSection worldConfigSection = worldsConfigFile.getWorldConfigSection(worldName);
WorldConfig worldConfig = new WorldConfig(worldConfigSection);
WorldConfig worldConfig = worldsConfigFile.getWorldConfig(worldName);
//todo
}

View File

@ -49,6 +49,10 @@ public class WorldsConfigFile {
? worldConfig.getConfigurationSection(worldName) : worldConfig.createSection(worldName);
}
public WorldConfig getWorldConfig(String worldName) {
return new WorldConfig(getWorldConfigSection(worldName));
}
public void deleteWorldConfigSection(String worldName) {
worldConfig.set(worldName, null);
}

View File

@ -38,14 +38,14 @@ class WorldConfigFileTest : TestWithMockBukkit() {
@Test
fun `Add a new world to config`() {
val worldConfig = WorldConfig(worldConfigFile.getWorldConfigSection("newworld"))
val worldConfig = worldConfigFile.getWorldConfig("newworld")
worldConfigFile.save()
compareConfigFile("worlds2.yml", "/newworld_worlds.yml")
}
@Test
fun `Updating existing world properties`() {
val worldConfig = WorldConfig(worldConfigFile.getWorldConfigSection("world"))
val worldConfig = worldConfigFile.getWorldConfig("world")
worldConfig.setProperty("adjust-spawn", true)
worldConfig.setProperty("alias", "newalias")
worldConfigFile.save()

View File

@ -25,7 +25,7 @@ class WorldConfigTest : TestWithMockBukkit() {
worldConfigFile = WorldsConfigFile(multiverseCore)
worldConfigFile.load()
worldConfig = WorldConfig(worldConfigFile.getWorldConfigSection("world"))
worldConfig = worldConfigFile.getWorldConfig("world")
}
@Test