SPIGOT-7675: Fix FoodComponent config deserialization

Be more lenient when converting floating point numbers during config
deserialization of item data.

By: blablubbabc <lukas@wirsindwir.de>
This commit is contained in:
CraftBukkit/Spigot 2024-05-31 07:14:09 +10:00
parent 79d9816660
commit 764529d82b

View File

@ -102,6 +102,19 @@ public final class SerializableMeta implements ConfigurationSerializable {
if (clazz.isInstance(object)) {
return clazz.cast(object);
}
// SPIGOT-7675 - More lenient conversion of floating point numbers from other number types:
if (clazz == Float.class || clazz == Double.class) {
if (Number.class.isInstance(object)) {
Number number = Number.class.cast(object);
if (clazz == Float.class) {
return clazz.cast(number.floatValue());
} else {
return clazz.cast(number.doubleValue());
}
}
}
if (object == null) {
if (!nullable) {
throw new NoSuchElementException(map + " does not contain " + field);