From 7828c9292614901f15e1e7f7144b989801e57899 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Sat, 2 Sep 2023 23:07:39 +0800 Subject: [PATCH] Add entryfee, spawning and spawn location --- .../worldnew/config/WorldConfig.java | 76 ++++++++++++++++++- .../worldnew/config/WorldConfigNodes.java | 50 +++++++++++- .../core/world/WorldConfigMangerTest.kt | 18 ++--- .../multiverse/core/world/WorldConfigTest.kt | 5 ++ src/test/resources/default_worlds.yml | 24 ++++++ src/test/resources/delete_worlds.yml | 12 +++ src/test/resources/newworld_worlds.yml | 36 +++++++++ src/test/resources/properties_worlds.yml | 24 ++++++ 8 files changed, 231 insertions(+), 14 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 a5b27cda..b6022c2d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java @@ -7,6 +7,8 @@ import com.onarandombox.MultiverseCore.worldnew.MVWorld; import io.vavr.control.Try; import org.bukkit.Difficulty; import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.jetbrains.annotations.NotNull; @@ -103,6 +105,22 @@ public class WorldConfig { return configHandle.set(configNodes.DIFFICULTY, difficulty); } + public double getEntryFeeAmount() { + return configHandle.get(configNodes.ENTRY_FEE_AMOUNT); + } + + public Try setEntryFeeAmount(double entryFeeAmount) { + return configHandle.set(configNodes.ENTRY_FEE_AMOUNT, entryFeeAmount); + } + + public Material getEntryFeeCurrency() { + return configHandle.get(configNodes.ENTRY_FEE_CURRENCY); + } + + public Try setEntryFeeCurrency(Material entryFeeCurrency) { + return configHandle.set(configNodes.ENTRY_FEE_CURRENCY, entryFeeCurrency); + } + public World.Environment getEnvironment() { return configHandle.get(configNodes.ENVIRONMENT); } @@ -199,8 +217,64 @@ public class WorldConfig { return configHandle.set(configNodes.SEED, seed); } + public Location getSpawnLocation() { + return configHandle.get(configNodes.SPAWN_LOCATION); + } + + public Try setSpawnLocation(Location spawnLocation) { + return configHandle.set(configNodes.SPAWN_LOCATION, spawnLocation); + } + + public boolean getSpawningAnimals() { + return configHandle.get(configNodes.SPAWNING_ANIMALS); + } + + public Try setSpawningAnimals(boolean spawningAnimals) { + return configHandle.set(configNodes.SPAWNING_ANIMALS, spawningAnimals); + } + + public int getSpawningAnimalsAmount() { + return configHandle.get(configNodes.SPAWNING_ANIMALS_AMOUNT); + } + + public Try setSpawningAnimalsAmount(int spawningAnimalsAmount) { + return configHandle.set(configNodes.SPAWNING_ANIMALS_AMOUNT, spawningAnimalsAmount); + } + + public List getSpawningAnimalsExceptions() { + return configHandle.get(configNodes.SPAWNING_ANIMALS_EXCEPTIONS); + } + + public Try setSpawningAnimalsExceptions(List spawningAnimalsExceptions) { + return configHandle.set(configNodes.SPAWNING_ANIMALS_EXCEPTIONS, spawningAnimalsExceptions); + } + + public boolean getSpawningMonsters() { + return configHandle.get(configNodes.SPAWNING_MONSTERS); + } + + public Try setSpawningMonsters(boolean spawningMonsters) { + return configHandle.set(configNodes.SPAWNING_MONSTERS, spawningMonsters); + } + + public int getSpawningMonstersAmount() { + return configHandle.get(configNodes.SPAWNING_MONSTERS_AMOUNT); + } + + public Try setSpawningMonstersAmount(int spawningMonstersAmount) { + return configHandle.set(configNodes.SPAWNING_MONSTERS_AMOUNT, spawningMonstersAmount); + } + + public List getSpawningMonstersExceptions() { + return configHandle.get(configNodes.SPAWNING_MONSTERS_EXCEPTIONS); + } + + public Try setSpawningMonstersExceptions(List spawningMonstersExceptions) { + return configHandle.set(configNodes.SPAWNING_MONSTERS_EXCEPTIONS, spawningMonstersExceptions); + } + public List getWorldBlacklist() { - return (List) configHandle.get(configNodes.WORLD_BLACKLIST); + return configHandle.get(configNodes.WORLD_BLACKLIST); } public Try setWorldBlacklist(List worldBlacklist) { 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 a2c84086..ef901ae2 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java @@ -7,6 +7,8 @@ import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType; import com.onarandombox.MultiverseCore.worldnew.MVWorld; import org.bukkit.Difficulty; import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.jetbrains.annotations.NotNull; @@ -68,6 +70,16 @@ public class WorldConfigNodes { }) .build()); + public final ConfigNode ENTRY_FEE_AMOUNT = node(ConfigNode.builder("entry-fee.amount", Double.class) + .defaultValue(0.0) + .name("entryfee-amount") + .build()); + + public final ConfigNode ENTRY_FEE_CURRENCY = node(ConfigNode.builder("entry-fee.currency", Material.class) + .defaultValue(Material.AIR) // TODO: Convert from material ID + .name("entryfee-currency") + .build()); + public final ConfigNode ENVIRONMENT = node(ConfigNode.builder("environment", World.Environment.class) .defaultValue(World.Environment.NORMAL) .name("environment") @@ -136,6 +148,40 @@ public class WorldConfigNodes { .name("seed") .build()); + public final ConfigNode SPAWN_LOCATION = node(ConfigNode.builder("spawn-location", Location.class) + .name("spawn-location") + .build()); + + public final ConfigNode SPAWNING_ANIMALS = node(ConfigNode.builder("spawning.animals.spawn", Boolean.class) + .defaultValue(true) + .name("spawning-animals") + .build()); + + public final ConfigNode SPAWNING_ANIMALS_AMOUNT = node(ConfigNode.builder("spawning.animals.amount", Integer.class) + .defaultValue(-1) + .name("spawning-animals-amount") + .build()); + + public final ConfigNode SPAWNING_ANIMALS_EXCEPTIONS = node(ConfigNode.builder("spawning.animals.exceptions", List.class) + .defaultValue(new ArrayList<>()) + .name("spawning-animals-exceptions") + .build()); + + public final ConfigNode SPAWNING_MONSTERS = node(ConfigNode.builder("spawning.monsters.spawn", Boolean.class) + .defaultValue(true) + .name("spawning-monsters") + .build()); + + public final ConfigNode SPAWNING_MONSTERS_AMOUNT = node(ConfigNode.builder("spawning.monsters.amount", Integer.class) + .defaultValue(-1) + .name("spawning-monsters-amount") + .build()); + + public final ConfigNode SPAWNING_MONSTERS_EXCEPTIONS = node(ConfigNode.builder("spawning.monsters.exceptions", List.class) + .defaultValue(new ArrayList<>()) + .name("spawning-monsters-exceptions") + .build()); + public final ConfigNode WORLD_BLACKLIST = node(ConfigNode.builder("world-blacklist", List.class) .defaultValue(new ArrayList<>()) .name("world-blacklist") @@ -150,8 +196,4 @@ public class WorldConfigNodes { } // TODO: Migrate color and style into alias - // TODO: spawning - // TODO: entryfee - // TODO: spawnLocation - // TODO: worldBlacklist } diff --git a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigMangerTest.kt b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigMangerTest.kt index cec4cdfc..0a60122c 100644 --- a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigMangerTest.kt +++ b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigMangerTest.kt @@ -13,7 +13,7 @@ import kotlin.test.assertNotNull class WorldConfigMangerTest : TestWithMockBukkit() { - private lateinit var worldConfigFile : WorldsConfigManager + private lateinit var worldConfigManager : WorldsConfigManager @BeforeTest fun setUp() { @@ -21,13 +21,13 @@ class WorldConfigMangerTest : TestWithMockBukkit() { assertNotNull(defaultConfig) File(Path.of(multiverseCore.dataFolder.absolutePath, "worlds2.yml").absolutePathString()).writeText(defaultConfig) - worldConfigFile = + worldConfigManager = WorldsConfigManager(multiverseCore) } @Test fun `World config is loaded`() { - assertTrue(worldConfigFile.isLoaded) + assertTrue(worldConfigManager.isLoaded) } @Test @@ -37,24 +37,24 @@ class WorldConfigMangerTest : TestWithMockBukkit() { @Test fun `Add a new world to config`() { - val worldConfig = worldConfigFile.addWorldConfig("newworld") - worldConfigFile.save() + val worldConfig = worldConfigManager.addWorldConfig("newworld") + worldConfigManager.save() compareConfigFile("worlds2.yml", "/newworld_worlds.yml") } @Test fun `Updating existing world properties`() { - val worldConfig = worldConfigFile.getWorldConfig("world") + val worldConfig = worldConfigManager.getWorldConfig("world") worldConfig.setProperty("adjust-spawn", true) worldConfig.setProperty("alias", "newalias") - worldConfigFile.save() + worldConfigManager.save() compareConfigFile("worlds2.yml", "/properties_worlds.yml") } @Test fun `Delete world section from config`() { - worldConfigFile.deleteWorldConfig("world") - worldConfigFile.save() + worldConfigManager.deleteWorldConfig("world") + worldConfigManager.save() compareConfigFile("worlds2.yml", "/delete_worlds.yml") } 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 4d8d2078..2c646c4d 100644 --- a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigTest.kt +++ b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigTest.kt @@ -2,6 +2,7 @@ package org.mvplugins.multiverse.core.world import com.onarandombox.MultiverseCore.worldnew.config.WorldConfig import com.onarandombox.MultiverseCore.worldnew.config.WorldsConfigManager +import org.bukkit.Location import org.mvplugins.multiverse.core.TestWithMockBukkit import java.io.File import java.nio.file.Path @@ -60,6 +61,10 @@ class WorldConfigTest : TestWithMockBukkit() { val blacklists = listOf("a", "b", "c") assertTrue(worldConfig.setProperty("world-blacklist", blacklists).isSuccess) assertEquals(blacklists, worldConfig.getProperty("world-blacklist").get()) + + val location = Location(null, 1.0, 2.0, 3.0) + assertTrue(worldConfig.setProperty("spawn-location", location).isSuccess) + assertEquals(location, worldConfig.getProperty("spawn-location").get()) } @Test diff --git a/src/test/resources/default_worlds.yml b/src/test/resources/default_worlds.yml index 52f9f910..3fe0f31d 100644 --- a/src/test/resources/default_worlds.yml +++ b/src/test/resources/default_worlds.yml @@ -6,6 +6,9 @@ world: auto-heal: true auto-load: true difficulty: NORMAL + entry-fee: + amount: 0.0 + currency: AIR environment: NORMAL gamemode: SURVIVAL generator: '' @@ -18,6 +21,15 @@ world: respawn-world: '' scale: 1.0 seed: -9223372036854775808 + spawning: + animals: + spawn: true + amount: -1 + exceptions: [] + monsters: + spawn: true + amount: -1 + exceptions: [] world-blacklist: [] world_nether: adjust-spawn: false @@ -27,6 +39,9 @@ world_nether: auto-heal: true auto-load: true difficulty: NORMAL + entry-fee: + amount: 0.0 + currency: AIR environment: NETHER gamemode: SURVIVAL generator: '' @@ -39,4 +54,13 @@ world_nether: respawn-world: '' scale: 1.0 seed: -9223372036854775808 + spawning: + animals: + spawn: true + amount: -1 + exceptions: [] + monsters: + spawn: true + amount: -1 + exceptions: [] world-blacklist: [] diff --git a/src/test/resources/delete_worlds.yml b/src/test/resources/delete_worlds.yml index 35f257a2..3cf1fee0 100644 --- a/src/test/resources/delete_worlds.yml +++ b/src/test/resources/delete_worlds.yml @@ -6,6 +6,9 @@ world_nether: auto-heal: true auto-load: true difficulty: NORMAL + entry-fee: + amount: 0.0 + currency: AIR environment: NETHER gamemode: SURVIVAL generator: '' @@ -18,4 +21,13 @@ world_nether: respawn-world: '' scale: 1.0 seed: -9223372036854775808 + spawning: + animals: + spawn: true + amount: -1 + exceptions: [] + monsters: + spawn: true + amount: -1 + exceptions: [] world-blacklist: [] diff --git a/src/test/resources/newworld_worlds.yml b/src/test/resources/newworld_worlds.yml index cf9df709..976c070c 100644 --- a/src/test/resources/newworld_worlds.yml +++ b/src/test/resources/newworld_worlds.yml @@ -6,6 +6,9 @@ world: auto-heal: true auto-load: true difficulty: NORMAL + entry-fee: + amount: 0.0 + currency: AIR environment: NORMAL gamemode: SURVIVAL generator: '' @@ -18,6 +21,15 @@ world: respawn-world: '' scale: 1.0 seed: -9223372036854775808 + spawning: + animals: + spawn: true + amount: -1 + exceptions: [] + monsters: + spawn: true + amount: -1 + exceptions: [] world-blacklist: [] world_nether: adjust-spawn: false @@ -27,6 +39,9 @@ world_nether: auto-heal: true auto-load: true difficulty: NORMAL + entry-fee: + amount: 0.0 + currency: AIR environment: NETHER gamemode: SURVIVAL generator: '' @@ -39,6 +54,15 @@ world_nether: respawn-world: '' scale: 1.0 seed: -9223372036854775808 + spawning: + animals: + spawn: true + amount: -1 + exceptions: [] + monsters: + spawn: true + amount: -1 + exceptions: [] world-blacklist: [] newworld: adjust-spawn: false @@ -48,6 +72,9 @@ newworld: auto-heal: true auto-load: true difficulty: NORMAL + entry-fee: + amount: 0.0 + currency: AIR environment: NORMAL gamemode: SURVIVAL generator: '' @@ -60,4 +87,13 @@ newworld: respawn-world: '' scale: 1.0 seed: -9223372036854775808 + spawning: + animals: + spawn: true + amount: -1 + exceptions: [] + monsters: + spawn: true + amount: -1 + exceptions: [] world-blacklist: [] diff --git a/src/test/resources/properties_worlds.yml b/src/test/resources/properties_worlds.yml index 48f59285..67a9cae9 100644 --- a/src/test/resources/properties_worlds.yml +++ b/src/test/resources/properties_worlds.yml @@ -6,6 +6,9 @@ world: auto-heal: true auto-load: true difficulty: NORMAL + entry-fee: + amount: 0.0 + currency: AIR environment: NORMAL gamemode: SURVIVAL generator: '' @@ -18,6 +21,15 @@ world: respawn-world: '' scale: 1.0 seed: -9223372036854775808 + spawning: + animals: + spawn: true + amount: -1 + exceptions: [] + monsters: + spawn: true + amount: -1 + exceptions: [] world-blacklist: [] world_nether: adjust-spawn: false @@ -27,6 +39,9 @@ world_nether: auto-heal: true auto-load: true difficulty: NORMAL + entry-fee: + amount: 0.0 + currency: AIR environment: NETHER gamemode: SURVIVAL generator: '' @@ -39,4 +54,13 @@ world_nether: respawn-world: '' scale: 1.0 seed: -9223372036854775808 + spawning: + animals: + spawn: true + amount: -1 + exceptions: [] + monsters: + spawn: true + amount: -1 + exceptions: [] world-blacklist: []