Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7675

FoodComponent config deserialization

XMLWordPrintable

    •  This server is running CraftBukkit version dev-Spigot-342f493-87d0a33 (MC: 1.20.6) (Implementing API version 1.20.6-R0.1-SNAPSHOT)
    • Yes

      Give command:

      /give @p paper[food={nutrition:1,saturation:1f,can_always_eat:true,eat_seconds:5f}] 1
      

      Serialized item data in config:

              ==: org.bukkit.inventory.ItemStack
              v: 3839
              type: PAPER
              meta:
                ==: ItemMeta
                meta-type: UNSPECIFIC
                food:
                  ==: Food
                  nutrition: 1
                  saturation: 1.0
                  can-always-eat: true
                  eat-seconds: 5.0
                  effects: []
      

      Error during deserialization:

      Caused by: org.bukkit.configuration.InvalidConfigurationException: Could not call constructor 'public org.bukkit.craftbukkit.v1_20_R4.inventory.components.CraftFoodComponent(java.util.Map)' of class org.bukkit.craftbukkit.v1_20_R4.inventory.components.CraftFoodComponent for deserialization
              at com.nisovin.shopkeepers.util.bukkit.ConfigUtils.loadConfigSafely(ConfigUtils.java:246) ~[?:?]
              at com.nisovin.shopkeepers.util.data.persistence.bukkit.BukkitConfigDataStore.loadFromString(BukkitConfigDataStore.java:61) ~[?:?]
              ... 20 more
      Caused by: java.lang.IllegalArgumentException: saturation(1.0) is not a valid class java.lang.Float
              at org.bukkit.craftbukkit.v1_20_R4.inventory.SerializableMeta.getObject(SerializableMeta.java:111) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:dev-Spigot-342f493-87d0a33]
              at org.bukkit.craftbukkit.v1_20_R4.inventory.components.CraftFoodComponent.<init>(CraftFoodComponent.java:33) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:dev-Spigot-342f493-87d0a33]
              at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[?:?]
              at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[?:?]
              at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[?:?]
              at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeViaCtor(ConfigurationSerialization.java:107) ~[spigot-api-1.20.6-R0.1-SNAPSHOT.jar:?]
              at org.bukkit.configuration.serialization.ConfigurationSerialization.deserialize(ConfigurationSerialization.java:145) ~[spigot-api-1.20.6-R0.1-SNAPSHOT.jar:?]
              at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(ConfigurationSerialization.java:209) ~[spigot-api-1.20.6-R0.1-SNAPSHOT.jar:?]
              at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:58) ~[spigot-api-1.20.6-R0.1-SNAPSHOT.jar:?]
      

      Snakeyaml probably loads this as double. There might also be cases in which the value is loaded as integer if users edit the value manually inside configs and omit the ".0" suffix on the number. In CraftFoodComponent we currently try to load these values as Float, without converting from other number types currently.

            blablubbabc blablubbabc
            blablubbabc blablubbabc
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: