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

Calling ItemStack#setType for items inside an Inventory will not update

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Invalid
    • None
    • None
    • OpenJDK 14 64-bit build 14+36 for Spigot 1.15.2 and CraftBukkit 1.15.2. OpenJDK 13 64-bit build 13+33 for Spigot 1.14.4 and CraftBukkit 1.14.4. Windows 7 Professional.

    • This server is running CraftBukkit version git-Spigot-a03b1fd-fc318cc (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)
    • Yes

    Description

      When placing an ItemStack inside a custom Inventory (created by Bukkit.createInventory), the item is shown in the Inventory. If the same ItemStack is then updated via ItemStack#setType(Material) to a different type, then reopening the same Inventory, the item will still have its old type shown, instead of the new type.

      I believe this is a bug, since the ItemStack updates itself (as per Javadocs: "Sets the type of this item" (italics of "this" not in original quote)), so readding the item to the inventory should not be necessary (since it's already in there). While having to reopen the Inventory for the viewer(s) is understandable, I would expect this action to show the new item, however the old item is still shown.

      I have tested this on Spigot 1.15.2 (git-Spigot-a03b1fd-fc318cc (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)); CraftBukkit 1.15.2 (git-Bukkit-fc318cc (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)); Spigot 1.14.4 (git-Spigot-56f8741-3e3818b (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)); and CraftBukkit 1.14.4 (git-Bukkit-009d8af (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)) and this issue occurs on all of them.

      To reproduce this issue make sure that the test plugin I attached below has been installed on a server. Start the server and login to the server as a player. Make sure that this player is an operator on the joined server. Then execute as this player via chat the command /gui open and notice the green wool in the top left corner of the now opened inventory. This is indeed as it should be. Now close the opened inventory and execute /gui change and no visible change should occur (as intended). Internally the ItemStack has been changed from green wool to red wool. Now execute /gui open yet again and notice how the item in the top-left corner of the again opened inventory is still green wool, instead of the expected red wool.

      The code of the sample plugin along with its plugin.yml can be seen here: https://gist.github.com/stefvanschie/0d6d67d6425d665be7529a0769b8b9aa

      Attachments

        Activity

          People

            Unassigned Unassigned
            stefvanschie Stef van Schie
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: