Skip to content

Implement pre via version injection support for spigot module#1446

Draft
ytnoos wants to merge 8 commits intoretrooper:2.0from
ytnoos:pre-via
Draft

Implement pre via version injection support for spigot module#1446
ytnoos wants to merge 8 commits intoretrooper:2.0from
ytnoos:pre-via

Conversation

@ytnoos
Copy link
Copy Markdown
Contributor

@ytnoos ytnoos commented Jan 25, 2026

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, an old version of this patch is used by both Grim and LPX.

By default, PacketEvents keeps the standard post-Via behavior.
Pre-Via support is enabled dynamically when a Pre-Via listener is registered: in order to do that just override isPreVia() in your listener:

@Override
public boolean isPreVia() {
    return true;
}

I apologize in advance for any errors and look forward to hearing from you if any changes or improvements to the code are needed.

@SpigotRCE
Copy link
Copy Markdown

Damn

@3add
Copy link
Copy Markdown

3add commented Jan 25, 2026

W

@florianreuth
Copy link
Copy Markdown

Pure ViaVersion evilness:tm:

@booky10
Copy link
Copy Markdown
Collaborator

booky10 commented Jan 25, 2026

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?

@ytnoos
Copy link
Copy Markdown
Contributor Author

ytnoos commented Jan 25, 2026

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?

@booky10
Copy link
Copy Markdown
Collaborator

booky10 commented Jan 25, 2026

The problem with settings is that they are shared globally across all plugins using packetevents (except when you're shading)
If some random plugin decides they want to disable pre-via injection, this affects all other plugins using packetevents and may lead to unexpected behavior

I can take a look at dynamic injection later

@retrooper
Copy link
Copy Markdown
Owner

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.

@ytnoos
Copy link
Copy Markdown
Contributor Author

ytnoos commented Jan 26, 2026

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

@NikV2
Copy link
Copy Markdown
Contributor

NikV2 commented Jan 30, 2026

Looking forward towards this pull request!

@ytnoos
Copy link
Copy Markdown
Contributor Author

ytnoos commented Jan 30, 2026

Tested on 1.8.8 and 1.21.8 and works well!

@retrooper
Copy link
Copy Markdown
Owner

I suppose we can start reviewing and editing this PR. I have not received any PR from Axionize, a Grim maintainer.

@retrooper
Copy link
Copy Markdown
Owner

So far, I've not been able to reach a resolution with the Grim team. I can start reviewing this PR starting on April 20th; feel free to send me reminders around that time. If possible, could you resolve the conflicts? @ytnoos

@ytnoos
Copy link
Copy Markdown
Contributor Author

ytnoos commented Apr 12, 2026

Don't review it yet. I'm still testing a few new things

@ytnoos ytnoos marked this pull request as draft April 12, 2026 14:39
@Dg32z
Copy link
Copy Markdown

Dg32z commented Apr 13, 2026

[17:31:19 INFO]: [packetevents] Failed to map the Packet ID 334 to a PacketType constant. Bound: CLIENT, Connection state: LOGIN, Server version: 1.20.4
[17:31:19 INFO]: [packetevents] Disconnected Dg32z_ due to an invalid packet!
[17:31:19 INFO]: Dg32z_ lost connection: Invalid packet

It seems that support for some server versions has been broken

@ytnoos
Copy link
Copy Markdown
Contributor Author

ytnoos commented Apr 13, 2026

[17:31:19 INFO]: [packetevents] Failed to map the Packet ID 334 to a PacketType constant. Bound: CLIENT, Connection state: LOGIN, Server version: 1.20.4 [17:31:19 INFO]: [packetevents] Disconnected Dg32z_ due to an invalid packet! [17:31:19 INFO]: Dg32z_ lost connection: Invalid packet

It seems that support for some server versions has been broken

Can you tell me client version and plugin list?

@Dg32z
Copy link
Copy Markdown

Dg32z commented Apr 13, 2026

[17:31:19 INFO]: [packetevents] Failed to map the Packet ID 334 to a PacketType constant. Bound: CLIENT, Connection state: LOGIN, Server version: 1.20.4 [17:31:19 INFO]: [packetevents] Disconnected Dg32z_ due to an invalid packet! [17:31:19 INFO]: Dg32z_ lost connection: Invalid packet
It seems that support for some server versions has been broken

Can you tell me client version and plugin list?

pl
[19:34:11 INFO]: Server Plugins (13):
[19:34:11 INFO]: Paper Plugins:
[19:34:11 INFO]: - PlugManX
[19:34:11 INFO]: Bukkit Plugins:
[19:34:11 INFO]: - CHAOS-BadWordFilter, Citizens, FastAsyncWorldEdit, LPX, LuckPerms, packetevents, PlaceholderAPI, spark, TAB, ViaBackwards
[19:34:11 INFO]: ViaRewind, ViaVersion
[19:34:12 INFO]: This server is running Paper version git-Paper-499 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: 9de3f75 on ver/1.20.4)
You are running the latest version
Previous version: 1.21.8-60-29c8822 (MC: 1.21.8)
[19:34:23 INFO]: UUID of player Dg32z_ is b2707b1a-668e-36d2-ac98-782173baa7b8
[19:34:23 INFO]: [packetevents] Failed to map the Packet ID 39465 to a PacketType constant. Bound: CLIENT, Connection state: LOGIN, Server version: 1.20.4
[19:34:23 INFO]: [packetevents] Disconnected null due to an invalid packet!
[19:34:23 INFO]: com.mojang.authlib.GameProfile@2b09b26[id=b2707b1a-668e-36d2-ac98-782173baa7b8,name=Dg32z_,properties={}] lost connection: Disconnected, while in configuration phase null
plugman unload
[19:34:26 INFO]: [PlugMan] You must specify a plugin.
[19:34:26 INFO]: - Command: Unload
[19:34:26 INFO]: - Description: Unload a plugin.
[19:34:26 INFO]: - Usage: plugman
ver
[19:34:27 INFO]: This server is running Paper version git-Paper-499 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: 9de3f75 on ver/1.20.4)
You are running the latest version
Previous version: 1.21.8-60-29c8822 (MC: 1.21.8)

@Dg32z
Copy link
Copy Markdown

Dg32z commented Apr 13, 2026

[17:31:19 INFO]: [packetevents] Failed to map the Packet ID 334 to a PacketType constant. Bound: CLIENT, Connection state: LOGIN, Server version: 1.20.4 [17:31:19 INFO]: [packetevents] Disconnected Dg32z_ due to an invalid packet! [17:31:19 INFO]: Dg32z_ lost connection: Invalid packet
It seems that support for some server versions has been broken

Can you tell me client version and plugin list?

ClientVersion: 1.20.4
It seems like this issue occurs in 1.20x server versions

@ytnoos
Copy link
Copy Markdown
Contributor Author

ytnoos commented Apr 14, 2026

@Dg32z try this version, apparently the encoder was not in the right spot compared to the compression.

I also fixed the fact that the PreViaInternalListener was always forcing packetevents to inject pre-via handlers.

@Dg32z
Copy link
Copy Markdown

Dg32z commented Apr 14, 2026

@Dg32z try this version, apparently the encoder was not in the right spot compared to the compression.

I also fixed the fact that the PreViaInternalListener was always forcing packetevents to inject pre-via handlers.

seem fixed
I tested it on 1.20.4 and 1.8.8, and it works well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants