retrooper / packetevents

PacketEvents is emerging as a strong contender in the realm of Minecraft packet processing libraries. Designed to simplify packet manipulation while delivering high performance, this powerful tool aims to demystify the complexities of projects utilizing packets.
GNU General Public License v3.0
503 stars 144 forks source link

Errors when using Spigot pluginmessage API on brand channel #776

Open Photon-GitHub opened 3 months ago

Photon-GitHub commented 3 months ago

Describe the bug Sending a plugin message directly via the spigot API on the brand channel will cause errors to appear and might even prevent the player from joining the server.

The call:

final ByteBuf buf = Unpooled.buffer();

ByteBufUtil.writeString(buf, "Some Spigot");

player.sendPluginMessage(AntiCheatAddition.getInstance(), MessageChannel.MC_BRAND_CHANNEL.getChannel().orElseThrow(), ByteBufUtil.toArray(buf));
buf.release()

The error:

[01:50:56] [Netty Server IO #1/ERROR]: Error sending packet clientbound/minecraft:custom_payload
io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:custom_payload'
        at net.minecraft.network.codec.IdDispatchCodec.a(SourceFile:55) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.codec.IdDispatchCodec.encode(SourceFile:14) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.PacketEncoder.a(SourceFile:26) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.PacketEncoder.encode(SourceFile:12) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:863) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:968) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:856) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:863) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:968) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:856) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.ChannelOutboundHandlerAdapter.write(ChannelOutboundHandlerAdapter.java:113) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at net.minecraft.network.NetworkManager$2.write(NetworkManager.java:543) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:940) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:966) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:934) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:984) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1025) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:306) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at net.minecraft.network.NetworkManager.c(NetworkManager.java:366) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.NetworkManager.lambda$sendPacket$12(NetworkManager.java:359) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
        at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]
Caused by: java.lang.ClassCastException: class net.minecraft.network.protocol.common.custom.DiscardedPayload cannot be cast to class net.minecraft.network.protocol.common.custom.BrandPayload (net.minecraft.network.protocol.common.custom.DiscardedPayload and net.minecraft.network.protocol.common.custom.BrandPayload are in unnamed module of loader java.net.URLClassLoader @736e9adb)
        at net.minecraft.network.codec.StreamCodec$6.encode(SourceFile:42) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.protocol.common.custom.CustomPacketPayload$1.a(SourceFile:52) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.protocol.common.custom.CustomPacketPayload$1.a(SourceFile:57) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.protocol.common.custom.CustomPacketPayload$1.encode(SourceFile:39) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.codec.StreamCodec$8.encode(SourceFile:81) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.codec.StreamCodec$9.a(SourceFile:97) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.codec.StreamCodec$9.encode(SourceFile:87) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        at net.minecraft.network.codec.IdDispatchCodec.a(SourceFile:53) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4166-Spigot-e2c1eee-ba2d49d]
        ... 31 more

Software brand Spigot 1.20.6

Plugins LuckPerms, PacketEvents, AntiCheatAddition

How To Reproduce

  1. Join with the 1.20.6 vanilla minecraft client.
  2. See error

Expected behavior No error appears for spigot API calls.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

booky10 commented 3 months ago

Are you sure this is a packetevents issue? Do you intercept any plugin message packets using packetevents?

This seems more like a spigot issue to me

Photon-GitHub commented 3 months ago

It worked fine before 1.20.5 and it is purely the Spigot API. Whether that API has been updated properly, I don't know. I do not use packetevents to intercept plugin messages, just packetevents being present causes players to no longer be able to join. Disabling that message sending and everything works again.