Implement pre via version injection support for spigot module#1446
Implement pre via version injection support for spigot module#1446ytnoos wants to merge 2 commits intoretrooper:2.0from
Conversation
|
Damn |
|
W |
|
Pure ViaVersion evilness:tm: |
|
Hm, I'm not quite sure whether it is a good idea to lock this behavior behind a setting - would it be possible to dynamically inject our handlers if someone wants to register a pre-via listener? |
Injection is mostly done during PacketEvents init, and since anyone can register listeners at any time, it would mean that in order to do it correctly, we would reinject server channel and all connected players the first time a pre-via listener is registered. I think it can be done but the possibility of creating new problems increases. Is it worth it? |
|
The problem with settings is that they are shared globally across all plugins using packetevents (except when you're shading) I can take a look at dynamic injection later |
|
After some thought, dynamic injection may actually be the smartest option here. Based on the type of listener the developer(s) register, a handler (pre or post ViaVersion) will be added to the pipeline (dynamically). If developers register both, then we will have two handlers for incoming packets and two for outgoing. I think this is actually a decent solution, the only issue is PacketEvents has an internal listener which, by default, listens post ViaVersion. So on PE installations, the post ViaVersion handler would always be there no matter what. |
|
I haven't tested this yet, let me know if the logic is fine. I couldn't find any other way to actually intercept registered listeners without exposing methods to EventManager that anyone could call |
|
Looking forward towards this pull request! |
|
Tested on 1.8.8 and 1.21.8 and works well! |
|
I suppose we can start reviewing and editing this PR. I have not received any PR from Axionize, a Grim maintainer. |
Since Retrooper gave us the opportunity to possibly accept the pre-via patch, here we are. I merged my patch with the fixes [1] [2] made by @Axionize, whom I thank very much for contributing and making this possible. Currently, this code is used by both Grim and LPX, so it can be considered fairly safe.
By default packetevents should maintain the normal behavior. This patch works only for the spigot module and in order to use it
PacketEventsSettings#preViaInjection(true)must be called. Once this is done, packetevents will inject twice into the handlers for both the decoder and the encoder, once before ViaVersion and once after.By default, all listeners will keep the default behavior. To create a pre-via listener, simply override the method inside your listener like this:
I apologize in advance for any errors and look forward to hearing from you if any changes or improvements to the code are needed.