mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-19 05:51:51 +01:00
Implement double serialization to fix scale config node
This commit is contained in:
parent
c0c9814c10
commit
68717d592c
@ -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> DOUBLE_SERIALIZER = new NodeSerializer<>() {
|
||||
@Override
|
||||
public Double deserialize(Object object, Class<Double> 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<Double> type) {
|
||||
return object;
|
||||
}
|
||||
};
|
||||
|
||||
private static final NodeSerializer<Locale> LOCALE_SERIALIZER = new NodeSerializer<>() {
|
||||
@Override
|
||||
public Locale deserialize(Object object, Class<Locale> 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);
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user