SPIGOT-7675: Fix FoodComponent config deserialization

Be more lenient when converting floating point numbers during config
deserialization of item data.
This commit is contained in:
blablubbabc 2024-05-31 07:14:09 +10:00 committed by md_5
parent b148ed3322
commit d6607c7dd6
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

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);