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

Opening an inventory from within an InventoryClickEvent triggers a player interaction

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Minor
    • None
    • None
    • git-Spigot-d4cbb64-2361cb8 (MC: 1.16.1)
    • Yes

    Description

      Programmatically opening an inventory from within an InventoryClickEvent listener causes a player interaction (i.e. as if the player right or left clicked without any inventory open). This only seems to happen if you click on an item in the existing inventory rather than an empty slot (i.e. InventoryAction of type PICKUP_*).

      Here is a simple piece of code to reproduce the behaviour:

      @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
      public void onInventoryClick(InventoryClickEvent event) {
      	Inventory inventory = Bukkit.createInventory(null, 18, "some title");
      	inventory.setItem(0, new ItemStack(Material.DIAMOND_SWORD));
      	((Player) event.getWhoClicked()).openInventory(inventory);
      }
      

      Simply open your usual player inventory. Click on any item you're carrying. A player interaction will be triggered.

      Opening inventories like this from within InventoryClickEvents is common amongst plugins that implement their own custom GUI, for example with paginated or multi-layered inventories. As an example, this is causing issues in Advanced Achievements (https://github.com/PyvesB/AdvancedAchievements/issues/783).

      Note that this worked fine with all Minecraft versions from 1.15 all the way back to at least 1.7, and only started happening in Spigot 1.16 builds.

      Thanks for reading.

      Attachments

        Activity

          People

            Unassigned Unassigned
            DarkPyves Pyves
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: