From cc02f26807ffbfaacca3f9a905f4849507cc47b7 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 28 May 2022 16:10:30 +0100 Subject: [PATCH] Fixed key registry --- .../eco/internal/spigot/data/EcoKeyRegistry.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt index 3e5e4fd8..23dddb14 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt @@ -29,19 +29,24 @@ class EcoKeyRegistry : KeyRegistry { } private fun validateKey(key: PersistentDataKey) { + val default = key.defaultValue + when (key.type) { - PersistentDataKeyType.INT -> if (key.defaultValue !is Int) { + PersistentDataKeyType.INT -> if (default !is Int) { throw IllegalArgumentException("Invalid Data Type! Should be Int") } - PersistentDataKeyType.DOUBLE -> if (key.defaultValue !is Double) { + PersistentDataKeyType.DOUBLE -> if (default !is Double) { throw IllegalArgumentException("Invalid Data Type! Should be Double") } - PersistentDataKeyType.BOOLEAN -> if (key.defaultValue !is Boolean) { + PersistentDataKeyType.BOOLEAN -> if (default !is Boolean) { throw IllegalArgumentException("Invalid Data Type! Should be Boolean") } - PersistentDataKeyType.STRING -> if (key.defaultValue !is String) { + PersistentDataKeyType.STRING -> if (default !is String) { throw IllegalArgumentException("Invalid Data Type! Should be String") } + PersistentDataKeyType.STRING_LIST -> if (default !is List<*> || default.firstOrNull() !is String?) { + throw IllegalArgumentException("Invalid Data Type! Should be String List") + } else -> throw NullPointerException("Null value found!") }