From 29f7883f9bcfa993d3b31a3dd2478dac7daabb0b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 20 Jul 2023 01:45:52 +0200 Subject: [PATCH] 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 --- Chroma-Core/pom.xml | 2 +- .../src/main/java/buttondevteam/lib/ChromaUtils.kt | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Chroma-Core/pom.xml b/Chroma-Core/pom.xml index 1a1b3c0..baa48ce 100755 --- a/Chroma-Core/pom.xml +++ b/Chroma-Core/pom.xml @@ -172,7 +172,7 @@ io.papermc.paper paper-api - 1.19.1-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT provided diff --git a/Chroma-Core/src/main/java/buttondevteam/lib/ChromaUtils.kt b/Chroma-Core/src/main/java/buttondevteam/lib/ChromaUtils.kt index a80510e..415ba65 100644 --- a/Chroma-Core/src/main/java/buttondevteam/lib/ChromaUtils.kt +++ b/Chroma-Core/src/main/java/buttondevteam/lib/ChromaUtils.kt @@ -30,12 +30,12 @@ object ChromaUtils { @JvmStatic fun convertNumber(number: Number, targetcl: Class): Number { return when { - targetcl == Long::class.javaPrimitiveType || Long::class.java.isAssignableFrom(targetcl) -> number.toLong() - targetcl == Int::class.javaPrimitiveType || Int::class.java.isAssignableFrom(targetcl) -> number.toInt() //Needed because the parser can get longs - targetcl == Short::class.javaPrimitiveType || Short::class.java.isAssignableFrom(targetcl) -> number.toShort() - targetcl == Byte::class.javaPrimitiveType || Byte::class.java.isAssignableFrom(targetcl) -> number.toByte() - targetcl == Float::class.javaPrimitiveType || Float::class.java.isAssignableFrom(targetcl) -> number.toFloat() - targetcl == Double::class.javaPrimitiveType || Double::class.java.isAssignableFrom(targetcl) -> number.toDouble() + targetcl == Long::class.javaPrimitiveType || Long::class.javaObjectType.isAssignableFrom(targetcl) -> number.toLong() + targetcl == Int::class.javaPrimitiveType || Int::class.javaObjectType.isAssignableFrom(targetcl) -> number.toInt() //Needed because the parser can get longs + targetcl == Short::class.javaPrimitiveType || Short::class.javaObjectType.isAssignableFrom(targetcl) -> number.toShort() + targetcl == Byte::class.javaPrimitiveType || Byte::class.javaObjectType.isAssignableFrom(targetcl) -> number.toByte() + targetcl == Float::class.javaPrimitiveType || Float::class.javaObjectType.isAssignableFrom(targetcl) -> number.toFloat() + targetcl == Double::class.javaPrimitiveType || Double::class.javaObjectType.isAssignableFrom(targetcl) -> number.toDouble() else -> number } }