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) { public void addWorld(String worldName) {
ConfigurationSection worldConfigSection = worldsConfigFile.getWorldConfigSection(worldName); WorldConfig worldConfig = worldsConfigFile.getWorldConfig(worldName);
WorldConfig worldConfig = new WorldConfig(worldConfigSection);
//todo //todo
saveWorldsConfig(); saveWorldsConfig();
} }
public void loadWorld(String worldName) { public void loadWorld(String worldName) {
ConfigurationSection worldConfigSection = worldsConfigFile.getWorldConfigSection(worldName); WorldConfig worldConfig = worldsConfigFile.getWorldConfig(worldName);
WorldConfig worldConfig = new WorldConfig(worldConfigSection);
//todo //todo
} }

View File

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

View File

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

View File

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