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

PlayerInteractEvent fired for certain inventory clicks

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • Windows 7 Professional
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14+36, mixed mode, sharing)

    • This server is running CraftBukkit version git-Spigot-c3a49df-dba91d2 (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)
    • Yes

      When cancelling an inventory click event for the click events DROP and CONTROL_DROP while looking at air, a PlayerInteractEvent is erroneously fired. Analyzing the traffic on the server (both incoming and outgoing) it can be noted how for these two actions a PacketPlayInArmAnimation packet is sent from the client to the server (this can be visually observed by a swing of the player's arm on the side of the screen). To my knowledge this is sent because the client want to drop the item in the inventory and therefore swings the player's arm. Because the internal code relies on this same animation packet to figure out when a player left clicks air, this inventory click causes such a PlayerInteractEvent to be fired. To my knowledge PlayerInteractEvent should never be fired for dropping items and it's under normal circumstances impossible for the player to interact with anything (not with air a block, or physical interactions such as pressure plates) when they have an opened inventory. My proposed suggestion to solve this issue is therefore to not call this PlayerInteractEvent in the given circumstance when the player has an open inventory.

      Steps on how to analyze the traffic on the server can be viewed here: https://wiki.vg/Debugging (some stacktraces are thrown, however the logging still works).

      Reproduction steps:

      • Install the attached plugin on a server by putting it in the plugins folder.
      • Stop the server if it was started before by executing the stop command either from the console or as a player with operator level 4.
      • Start the server.
      • Join the test server as a player.
      • Rotate your head so you're not directly in line-of-sight with a non-air block (e.g. face directly upward to the sky).
      • Open the inventory by executing the gui command as a player.
      • Hover with your mouse over the apples in the first slot of the opened inventory and press the drop button (either with or without holding the control button at the same time).
      • Note the debug message in the console.

      The code for the reproduction plugin can be found here: https://paste.gg/p/anonymous/bdd21c3284bc4065b9e63a2f1cbbd68f.

      This bug occurs on Spigot 1.16.1 (CraftBukkit version git-Spigot-c3a49df-dba91d2 (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)); and CraftBukkit 1.16.1 (CraftBukkit version git-Bukkit-dba91d2 (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)), but not on Spigot 1.15.2 (CraftBukkit version git-Spigot-a99063f-be6aaf0 (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)); and CraftBukkit 1.15.2 (CraftBukkit version git-Bukkit-be6aaf0 (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)).

      My reasoning for why this does not work on 1.15.2 is because the client does not show an arm animation when dropping items from the inventory and therefore likely also doesn't send this packet to the server.

            Unassigned Unassigned
            stefvanschie Stef van Schie
            Votes:
            5 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: