Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlayerPickItemEvent should be an InventoryEvent #11372

Open
codeHusky opened this issue Sep 7, 2024 · 5 comments
Open

PlayerPickItemEvent should be an InventoryEvent #11372

codeHusky opened this issue Sep 7, 2024 · 5 comments
Labels
status: needs triage type: bug Something doesn't work as it was intended to.

Comments

@codeHusky
Copy link

codeHusky commented Sep 7, 2024

Expected behavior

The relevant packet for PlayerPickItemEvent (ServerboundPickItemPacket) is used by some mods to quick move items through the inventory to the player's hand. This event should extend InventoryEvent - it has all relevant Inventory context to provide the necessary information for an InventoryEvent.

Observed/Actual behavior

When sending a ServerboundPickItemPacket on slot 9, this event will fire and cause inventory manipulation without triggering any InventoryEvent (such as an InventoryClickEvent). This event also does not extend InventoryEvent, making it semi-invisible to Javadocs browsing for trying to handle Inventory-related exploits and bugs.

Steps/models to reproduce

  1. Implement a system utilizing InventoryEvents to prevent players from moving items
  2. Trigger a ServerboundPickItemPacket on a relevant slot
  3. PlayerPickItemEvent will fire, but no InventoryEvents will fire. The inventory will, however, still be mutated.

Plugin and Datapack List

[22:05:57 INFO]: Server Plugins (21):
[22:05:57 INFO]: Paper Plugins:
[22:05:57 INFO]:  - BKCommonLib
[22:05:57 INFO]: Bukkit Plugins:
[22:05:57 INFO]:  - Essentials, FastAsyncWorldEdit, GSit, helper, helper-sql, HuskyScreen, LuckPerms, Multiverse-Core, Multiverse-NetherPortals, packetevents
[22:05:57 INFO]:  *PlasmoDynamicSources, PlasmoVoice, PlugManX, ProtocolLib, pv-addon-lavaplayer-lib, spark, SubserverAdditions, Train_Carts, ViaVersion, WorldGuard
[22:06:09 INFO]: There are 2 data pack(s) enabled: [vanilla (built-in)], [file/bukkit (world)]
[22:06:09 INFO]: There are no more data packs available

Paper version

Unknown version
Previous version: git-Paper-280 (MC: 1.20.2)

Note: This paper fork only has small alterations for how Maps are updated and does not have any sweeping changes

Other

No response

@codeHusky codeHusky added status: needs triage type: bug Something doesn't work as it was intended to. labels Sep 7, 2024
@papermc-projects papermc-projects bot moved this to 🕑 Needs Triage in Issues: Bugs Sep 7, 2024
@electronicboy
Copy link
Member

electronicboy commented Sep 7, 2024

The event is a PlayerEvent, so we can't really extend InventoryEvent; I'm also not really sure what mutations this event is supposed to be doing, all it really seems to do is change the selected slot?

oh, it moves items around in a players inventory, bleh...

@codeHusky
Copy link
Author

codeHusky commented Sep 7, 2024

Yeah, to be fully clear, if you have an item in (for example) Slot 9 and fire that packet for it, it will move into the player's held inventory slot. This caused me several hours of debugging headache until I just finally caved and used the reporting player's modpack and a packet capture and, sure enough, it was doing some bizarre crap when shift-right-clicking items in the inventory.

Logging all relevant Inventory events looked identical to my own when trying to repro, but I couldn't get the dupe to occur no matter what in Vanilla. It's some odd, unused vanilla behavior or something.

@AjayAntoIsDev
Copy link

I dont understand how this could cause a dupe it just looks like a desync

@AjayAntoIsDev
Copy link

also could you link the modpack that causes the issue?

@codeHusky
Copy link
Author

codeHusky commented Sep 13, 2024

I dont understand how this could cause a dupe it just looks like a desync

The event does not trigger a dupe of any kind on its own. This is a developer UX issue on one hand, and an oversight in the API on the other. PlayerPickItemEvent is not built with the consideration that it can modify non-creative inventories in mind, so it does not extend InventoryEvent or provide any important context. This makes it somewhat invisible to folks making custom GUIs. There are likely many plugins that don't consider this event.

also could you link the modpack that causes the issue?

This is the modpack. It's ~175mb. I believe the specific mod here may be MouseTweaks or a different inventory QOL mod - it's the behavior where it swaps an item into your hotbar when it's consumed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage type: bug Something doesn't work as it was intended to.
Projects
Status: 🕑 Needs Triage
Development

No branches or pull requests

3 participants