diff --git a/src/main/java/org/mvplugins/multiverse/core/configuration/functions/DefaultSerializerProvider.java b/src/main/java/org/mvplugins/multiverse/core/configuration/functions/DefaultSerializerProvider.java index b4e54d5c..8eef68f3 100644 --- a/src/main/java/org/mvplugins/multiverse/core/configuration/functions/DefaultSerializerProvider.java +++ b/src/main/java/org/mvplugins/multiverse/core/configuration/functions/DefaultSerializerProvider.java @@ -5,6 +5,7 @@ import java.util.Locale; import java.util.Map; import co.aikar.commands.ACFUtil; +import com.dumptruckman.minecraft.util.Logging; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -71,6 +72,22 @@ public final class DefaultSerializerProvider { } }; + private static final NodeSerializer DOUBLE_SERIALIZER = new NodeSerializer<>() { + @Override + public Double deserialize(Object object, Class type) { + if (object instanceof Double number) { + return number; + } + Logging.finer("Converting %s to double", object); + return Double.parseDouble(String.valueOf(object)); + } + + @Override + public Object serialize(Double object, Class type) { + return object; + } + }; + private static final NodeSerializer LOCALE_SERIALIZER = new NodeSerializer<>() { @Override public Locale deserialize(Object object, Class type) { @@ -89,6 +106,7 @@ public final class DefaultSerializerProvider { static { addDefaultSerializer(Boolean.class, BOOLEAN_SERIALIZER); + addDefaultSerializer(Double.class, DOUBLE_SERIALIZER); addDefaultSerializer(Locale.class, LOCALE_SERIALIZER); } 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 25b58c92..ba060f83 100644 --- a/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigTest.kt +++ b/src/test/java/org/mvplugins/multiverse/core/world/WorldConfigTest.kt @@ -13,6 +13,7 @@ class WorldConfigTest : TestWithMockBukkit() { private lateinit var worldConfigManager : WorldsConfigManager private lateinit var worldConfig : WorldConfig + private lateinit var worldNetherConfig : WorldConfig @BeforeTest fun setUp() { @@ -26,13 +27,18 @@ class WorldConfigTest : TestWithMockBukkit() { assertTrue(worldConfigManager.load().isSuccess) worldConfig = worldConfigManager.getWorldConfig("world").orNull.takeIf { it != null } ?: run { throw IllegalStateException("WorldConfig for world is not available") } - assertNotNull(worldConfig); + assertNotNull(worldConfig) + worldNetherConfig = worldConfigManager.getWorldConfig("world_nether").orNull.takeIf { it != null } ?: run { + throw IllegalStateException("WorldConfig for world is not available") } + assertNotNull(worldNetherConfig); } @Test fun `Getting existing world property with getProperty returns expected value`() { assertEquals("my world", worldConfig.stringPropertyHandle.getProperty("alias").get()) assertEquals(false, worldConfig.stringPropertyHandle.getProperty("hidden").get()) + assertEquals(1.0, worldConfig.stringPropertyHandle.getProperty("scale").get()) + assertEquals(8.0, worldNetherConfig.stringPropertyHandle.getProperty("scale").get()) } @Test @@ -55,7 +61,7 @@ class WorldConfigTest : TestWithMockBukkit() { assertTrue(worldConfig.stringPropertyHandle.setProperty("alias", "abc").isSuccess) assertEquals("abc", worldConfig.stringPropertyHandle.getProperty("alias").get()) - assertTrue(worldConfig.stringPropertyHandle.setProperty("scale", 2.0).isSuccess) + assertTrue(worldConfig.stringPropertyHandle.setProperty("scale", "2.0").isSuccess) assertEquals(2.0, worldConfig.stringPropertyHandle.getProperty("scale").get()) val blacklists = listOf("a", "b", "c") diff --git a/src/test/resources/default_worlds.yml b/src/test/resources/default_worlds.yml index 5a40e2a1..57ba17ba 100644 --- a/src/test/resources/default_worlds.yml +++ b/src/test/resources/default_worlds.yml @@ -22,7 +22,7 @@ world: portal-form: ALL pvp: true respawn-world: '' - scale: 1.0 + scale: '1.0' seed: -9223372036854775808 spawn-location: ==: MVNullLocation (It's a bug if you see this in your config file) @@ -61,7 +61,7 @@ world_nether: portal-form: ALL pvp: true respawn-world: '' - scale: 1.0 + scale: 8 seed: -9223372036854775808 spawn-location: ==: MVNullLocation (It's a bug if you see this in your config file)