Fix number conversion in configs

- java.lang.Integer could not be cast to java.lang.Long and it was so confusing for so long
- Int::class.java is int.class instead of Integer.class like I thought
This commit is contained in:
Norbi Peti 2023-07-20 01:45:52 +02:00
parent 822b2a5a67
commit 29f7883f9b
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 7 additions and 7 deletions

View file

@ -172,7 +172,7 @@
<dependency> <dependency>
<groupId>io.papermc.paper</groupId> <groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.19.1-R0.1-SNAPSHOT</version> <version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -30,12 +30,12 @@ object ChromaUtils {
@JvmStatic @JvmStatic
fun convertNumber(number: Number, targetcl: Class<out Number>): Number { fun convertNumber(number: Number, targetcl: Class<out Number>): Number {
return when { return when {
targetcl == Long::class.javaPrimitiveType || Long::class.java.isAssignableFrom(targetcl) -> number.toLong() targetcl == Long::class.javaPrimitiveType || Long::class.javaObjectType.isAssignableFrom(targetcl) -> number.toLong()
targetcl == Int::class.javaPrimitiveType || Int::class.java.isAssignableFrom(targetcl) -> number.toInt() //Needed because the parser can get longs targetcl == Int::class.javaPrimitiveType || Int::class.javaObjectType.isAssignableFrom(targetcl) -> number.toInt() //Needed because the parser can get longs
targetcl == Short::class.javaPrimitiveType || Short::class.java.isAssignableFrom(targetcl) -> number.toShort() targetcl == Short::class.javaPrimitiveType || Short::class.javaObjectType.isAssignableFrom(targetcl) -> number.toShort()
targetcl == Byte::class.javaPrimitiveType || Byte::class.java.isAssignableFrom(targetcl) -> number.toByte() targetcl == Byte::class.javaPrimitiveType || Byte::class.javaObjectType.isAssignableFrom(targetcl) -> number.toByte()
targetcl == Float::class.javaPrimitiveType || Float::class.java.isAssignableFrom(targetcl) -> number.toFloat() targetcl == Float::class.javaPrimitiveType || Float::class.javaObjectType.isAssignableFrom(targetcl) -> number.toFloat()
targetcl == Double::class.javaPrimitiveType || Double::class.java.isAssignableFrom(targetcl) -> number.toDouble() targetcl == Double::class.javaPrimitiveType || Double::class.javaObjectType.isAssignableFrom(targetcl) -> number.toDouble()
else -> number else -> number
} }
} }