Fix CustomPacketPayload for MC 1.21.11+ / Paper 26 (Id record, DiscardedPayload, serialize)#3622
Open
rkfsociety wants to merge 4 commits into
Open
Fix CustomPacketPayload for MC 1.21.11+ / Paper 26 (Id record, DiscardedPayload, serialize)#3622rkfsociety wants to merge 4 commits into
rkfsociety wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Improves ProtocolLib’s compatibility with modern CustomPacketPayload implementations (MC 1.21.11+ / Paper 26.x) by hardening key extraction and payload serialization, and adjusts outbound payload construction to satisfy newer network codec expectations. Also refactors the Spigot updater worker into a top-level class to avoid runtime classloading issues.
Changes:
- Resolve
CustomPacketPayloadkeys via chained accessors (supportingIdrecord patterns) and more robust nested type/constructor discovery. - Serialize payload bodies via a concrete-class method lookup when the interface no longer exposes a suitable
write(...)method; add abyte[]reflection fallback for unknown payloads. - Prefer constructing
DiscardedPayload(id, byte[])when present to avoid outbound codecClassCastException; moveSpigotUpdateRunnableto a top-level class and addsetRemoteVersion.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/main/java/com/comphenix/protocol/wrappers/CustomPacketPayloadWrapper.java | Updates key/Id resolution, serialization lookup strategy, and outbound handle construction (including DiscardedPayload path). |
| src/main/java/com/comphenix/protocol/updater/SpigotUpdateRunnable.java | Introduces top-level update worker runnable used by SpigotUpdater. |
| src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java | Switches to the top-level runnable and exposes a setter for remoteVersion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+357
to
+358
| Object sample = MinecraftReflection.getPacketDataSerializer(Unpooled.buffer()); | ||
| serializerArgumentClassCache = c = sample.getClass(); |
Comment on lines
+427
to
+429
| Object serializer = MinecraftReflection.getPacketDataSerializer(buffer); | ||
| serialize.invoke(payload, serializer); | ||
| return StreamSerializer.getDefault().getBytesAndRelease(buffer); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improves ProtocolLib compatibility with
CustomPacketPayloadon Minecraft 1.21.11+ and Paper 26.x (including Folia): correct key extraction, body serialization, outbound payloads that the vanilla network codec accepts, and a small updater robustness fix.Problems
Identifier/ResourceLocationdirectly.getId()returns the nestedIdrecord; the Mojang identifier comes from a nested accessor (e.g.id()). The previous fuzzy match failed during<clinit>withExceptionInInitializerError.Id, so resolvingCustomPacketPayload$Idby name alone is unreliable. The PR uses the return type of the bridge method (e.g.getId()) andgetDeclaredConstructorsfor the record constructor.void *(ByteBuf)on the interface. Serialization is a single-argvoidmethod whose parameter must accept the realFriendlyByteBuf(or compatible) instance returned byMinecraftReflection.getPacketDataSerializer. The PR falls back to a BFS over the type hierarchy and matches parameters withparamType.isAssignableFrom(actualSerializerClass).CUSTOM_PAYLOADencoding — The play codec path casts payloads tonet.minecraft.network.protocol.common.custom.DiscardedPayload. A ByteBuddy-generatedCustomPacketPayloadimplementation is not aDiscardedPayload, which causedClassCastExceptionwhen sending (e.g. plugin channels). WhenDiscardedPayload(identifier, byte[])exists (Paper 26+),newHandle()uses that constructor instead of ByteBuddy.SpigotUpdater—NoClassDefFoundErrorforSpigotUpdater$SpigotUpdateRunnablein some setups. The inner runnable was moved to a top-level classSpigotUpdateRunnable.Changes (files)
CustomPacketPayloadWrapper.javaDiscardedPayloadpath; broader serialize + Id record resolution;byte[]fallback when reading unknown payloadsSpigotUpdateRunnable.javaSpigotUpdaterusesnew SpigotUpdateRunnable(this)SpigotUpdater.javasetRemoteVersion; trim importsTesting
./gradlew compileJava,./gradlew shadowJar— OKCustomPacketPayloadWrapperstatic init failures; noClassCastExceptionon outboundclientbound/minecraft:custom_payloadNotes for reviewers
DiscardedPayload(id, byte[])is absent (older versions), behavior falls back to the existing ByteBuddyProtocolLibCustomPacketPayloadpath.Idrecord + ByteBuddy branch remains for versions that needgetId()→Idbut do not yet use theDiscardedPayloadoutbound constructor.