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

Items with boolean-literal-like Strings in PersistentDataContainer are deserialized as booleans

XMLWordPrintable

    • This server is running CraftBukkit version git-Spigot-a19903d-e1ebdd9 (MC: 1.16.4) (Implementing API version 1.16.4-R0.1-SNAPSHOT)
    • Yes

       

      1. Create an ItemStack and set some boolean-like String value (e.g. testplugin:value: 'TRUE')
      2. Serialize it to YAML (the code below also saves it to a file because it's its main purpose)
      3. Deserizlize the ItemStack from the output code and the value has become 1b
      public void onEnable() {
          File saveFile = new File(getDataFolder(), "test.yml");
          
          try {
              FileConfiguration configuration = new YamlConfiguration();
              ItemStack item = new ItemStack(Material.STONE);
              ItemMeta meta = item.getItemMeta();
              meta.getPersistentDataContainer().set(new NamespacedKey(this, "value"), PersistentDataType.STRING, "TRUE");
              item.setItemMeta(meta);
              configuration.set("item", item);
              configuration.save(saveFile);
      
              // SAVED
              getLogger().info(configuration.saveToString());
      
          } catch (IOException e) {
              e.printStackTrace();
          }
      
          try {
              FileConfiguration configuration = new YamlConfiguration();
              configuration.load(saveFile);
      
              // LOADED
              getLogger().info(configuration.saveToString());
      
          } catch (IOException | InvalidConfigurationException e) {
              e.printStackTrace();
          }
      }
      

       

      Output:

      [20:34:51] [Server thread/INFO]: [TestPlugin] item:
        ==: org.bukkit.inventory.ItemStack
        v: 2584
        type: STONE
        meta:
          ==: ItemMeta
          meta-type: UNSPECIFIC
          PublicBukkitValues:
            testplugin:value: 'TRUE'
      [20:34:51] [Server thread/INFO]: [TestPlugin] item:
        ==: org.bukkit.inventory.ItemStack
        v: 2584
        type: STONE
        meta:
          ==: ItemMeta
          meta-type: UNSPECIFIC
          PublicBukkitValues:
            testplugin:value: 1b

            Unassigned Unassigned
            Chunk Dmitry Chankov
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: