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

ItemStack#isSimilar() no longer work after the item is deserialized

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

      So it is quite straight forward.

      Whenever an item's name is modified by the anvil, serialized, and then de-serialized, then isSimilar() now no longer able to tell they are the similar items.

      Take a look at the screenshots for details.

      Steps:

      1. Rename any item with anvil
      2. Copy the item through creative inventory (As shown in the screenshot)
      3. Check if they are indeed similar. At this point, they are similar as shown in screenshot.
      4. Now, do the following steps
        1. Save item using the FileConfiguration (using getConfig() method of the JavaPlugin class)
        2. Save the FileConfiguration into String
        3. Create a new YamlConfiguration and load the serialized String from 4.2.
        4. Get the ItemStack from the YamlConfiguration
      5. Now, again, check if they are similar just like I did in process 3.
      6. Now isSimilar() returns false for some unknown reason.

      Since the toString() of both ItemStack shows exactly same output, I assume something is internally failing.

      I think this is a major issue since it's a quite basic functionality. Item name is something that can be easily changed in-game without any plugins. Plugins that rely on isSimilar() method will be severely impacted by this problem.

      Thanks!

      PS) test code attached here

       

            Unassigned Unassigned
            wysohn wysohn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: