From 42eadd91a5d2acb5e0cb2dd03c89cebcfeb1e3bb Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:00:59 +0800 Subject: [PATCH 1/2] Adda remaining properties methods to WorldConfig --- .../worldnew/config/WorldConfig.java | 148 +++++++++++++++++- .../worldnew/config/WorldConfigNodes.java | 2 +- .../core/world/WorldConfigFileTest.kt | 2 +- 3 files changed, 146 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java index 926f77a7..22c502e4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java @@ -2,7 +2,11 @@ package com.onarandombox.MultiverseCore.worldnew.config; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.configuration.handle.ConfigurationSectionHandle; +import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType; import io.vavr.control.Try; +import org.bukkit.Difficulty; +import org.bukkit.GameMode; +import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,22 +35,158 @@ public class WorldConfig { return configHandle.set(name, value); } - public void setAlias(String alias) { - configHandle.set(configNodes.ALIAS, alias); + public boolean getAdjustSpawn() { + return configHandle.get(configNodes.ADJUST_SPAWN); + } + + public Try setAdjustSpawn(boolean adjustSpawn) { + return configHandle.set(configNodes.ADJUST_SPAWN, adjustSpawn); } public @Nullable String getAlias() { return configHandle.get(configNodes.ALIAS); } - public void setHidden(boolean hidden) { - configHandle.set(configNodes.HIDDEN, hidden); + public Try setAlias(String alias) { + return configHandle.set(configNodes.ALIAS, alias); + } + + public boolean getAllowFlight() { + return configHandle.get(configNodes.ALLOW_FLIGHT); + } + + public Try setAllowFlight(boolean allowFlight) { + return configHandle.set(configNodes.ALLOW_FLIGHT, allowFlight); + } + + public boolean getAllowWeather() { + return configHandle.get(configNodes.ALLOW_WEATHER); + } + + public Try setAllowWeather(boolean allowWeather) { + return configHandle.set(configNodes.ALLOW_WEATHER, allowWeather); + } + + public boolean getAutoHeal() { + return configHandle.get(configNodes.AUTO_HEAL); + } + + public Try setAutoHeal(boolean autoHeal) { + return configHandle.set(configNodes.AUTO_HEAL, autoHeal); + } + + public boolean getAutoLoad() { + return configHandle.get(configNodes.AUTO_LOAD); + } + + public Try setAutoLoad(boolean autoLoad) { + return configHandle.set(configNodes.AUTO_LOAD, autoLoad); + } + + public Difficulty getDifficulty() { + return configHandle.get(configNodes.DIFFICULTY); + } + + public Try setDifficulty(Difficulty difficulty) { + return configHandle.set(configNodes.DIFFICULTY, difficulty); + } + + public World.Environment getEnvironment() { + return configHandle.get(configNodes.ENVIRONMENT); + } + + public Try setEnvironment(World.Environment environment) { + return configHandle.set(configNodes.ENVIRONMENT, environment); + } + + public GameMode getGamemode() { + return configHandle.get(configNodes.GAMEMODE); + } + + public Try setGamemode(GameMode gamemode) { + return configHandle.set(configNodes.GAMEMODE, gamemode); + } + + public @Nullable String getGenerator() { + return configHandle.get(configNodes.GENERATOR); + } + + public Try setGenerator(String generator) { + return configHandle.set(configNodes.GENERATOR, generator); } public boolean isHidden() { return configHandle.get(configNodes.HIDDEN); } + public Try setHidden(boolean hidden) { + return configHandle.set(configNodes.HIDDEN, hidden); + } + + public boolean getHunger() { + return configHandle.get(configNodes.HUNGER); + } + + public Try setHunger(boolean hunger) { + return configHandle.set(configNodes.HUNGER, hunger); + } + + public boolean getKeepSpawnInMemory() { + return configHandle.get(configNodes.KEEP_SPAWN_IN_MEMORY); + } + + public Try setKeepSpawnInMemory(boolean keepSpawnInMemory) { + return configHandle.set(configNodes.KEEP_SPAWN_IN_MEMORY, keepSpawnInMemory); + } + + public int getPlayerLimit() { + return configHandle.get(configNodes.PLAYER_LIMIT); + } + + public Try setPlayerLimit(int playerLimit) { + return configHandle.set(configNodes.PLAYER_LIMIT, playerLimit); + } + + public AllowedPortalType getPortalForm() { + return configHandle.get(configNodes.PORTAL_FORM); + } + + public Try setPortalForm(AllowedPortalType portalForm) { + return configHandle.set(configNodes.PORTAL_FORM, portalForm); + } + + public boolean getPvp() { + return configHandle.get(configNodes.PVP); + } + + public Try setPvp(boolean pvp) { + return configHandle.set(configNodes.PVP, pvp); + } + + public String getRespawnWorld() { + return configHandle.get(configNodes.RESPAWN_WORLD); + } + + public Try setRespawnWorld(String respawnWorld) { + return configHandle.set(configNodes.RESPAWN_WORLD, respawnWorld); + } + + public double getScale() { + return configHandle.get(configNodes.SCALE); + } + + public Try setScale(double scale) { + return configHandle.set(configNodes.SCALE, scale); + } + + public @Nullable String getSeed() { + return configHandle.get(configNodes.SEED); + } + + public Try setSeed(String seed) { + return configHandle.set(configNodes.SEED, seed); + } + public List getWorldBlacklist() { return (List) configHandle.get(configNodes.WORLD_BLACKLIST); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java index 12bfc65d..6197d6b7 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java @@ -126,7 +126,7 @@ public class WorldConfigNodes { .name("world-blacklist") .build()); - //todo: color and style + //todo: Migrate color and style into alias //todo: spawning //todo: entryfee //todo: spawnLocation diff --git a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigFileTest.kt b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigFileTest.kt index cea40d17..8bef3703 100644 --- a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigFileTest.kt +++ b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigFileTest.kt @@ -66,4 +66,4 @@ class WorldConfigFileTest : TestWithMockBukkit() { assertNotNull(configCompare) assertEquals(configCompare, config) } -} \ No newline at end of file +} From 6effeacd1b1257ea67c3f7c4f2e52ea7bf527b53 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:20:25 +0800 Subject: [PATCH 2/2] Add getWorldConfig method --- .../onarandombox/MultiverseCore/worldnew/WorldManager.java | 6 ++---- .../MultiverseCore/worldnew/config/WorldsConfigFile.java | 4 ++++ .../mvplugins/multiverse/core/world/WorldConfigFileTest.kt | 4 ++-- .../org/mvplugins/multiverse/core/world/WorldConfigTest.kt | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java index 097950bb..4a0211b3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java @@ -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 } diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigFile.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigFile.java index a51a986b..1c67c5a8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigFile.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigFile.java @@ -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); } diff --git a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigFileTest.kt b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigFileTest.kt index 8bef3703..646e5b07 100644 --- a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigFileTest.kt +++ b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigFileTest.kt @@ -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() diff --git a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigTest.kt b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigTest.kt index 5d57836b..3adc24d8 100644 --- a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigTest.kt +++ b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigTest.kt @@ -25,7 +25,7 @@ class WorldConfigTest : TestWithMockBukkit() { worldConfigFile = WorldsConfigFile(multiverseCore) worldConfigFile.load() - worldConfig = WorldConfig(worldConfigFile.getWorldConfigSection("world")) + worldConfig = worldConfigFile.getWorldConfig("world") } @Test