ProtocolLib

3M Downloads

Problem with Scoreboard 1.21 NumberFormats

BigBag3000 opened this issue · 1 comments

commented

Describe the question
Hi, I created a healthbar on ProtocolLib and it worked fine. Now that version 1.21 is out, I have updated the server and am having problems with ProtocolLib. I tried to decipher your documentation, but it is terribly illegible and inconsistent with the real situation.

Documentation:
image

My plugin debug: (I did the debugging directly under packet.getModifier().writeDefaults();)
image

Why don't I have a boolean field?

My Code: (

ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
final PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
packet.getModifier().writeDefaults();
packet.getStrings().write(0, id);
packet.getIntegers().write(0,0);
packet.getChatComponents().write(0, WrappedChatComponent.fromJson(ComponentSerializer.toString(component)));
packet.getEnumModifier(EnumWrappers.RenderType.class, EnumWrappers.getRenderTypeClass()).write(0, EnumWrappers.RenderType.HEARTS);
protocolManager.sendServerPacket(player, packet);
This is causing my server to crash.

[12:52:41 ERROR]: Error sending packet clientbound/minecraft:set_objective (skippable? false) io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:set_objective' at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:53) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:20) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:26) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:12) ~[paper-1.21.jar:1.21-47-62ed302] 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.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:120) ~[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.Connection$2.write(Connection.java:756) ~[paper-1.21.jar:1.21-47-62ed302] 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.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1020) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final] at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:311) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final] at ProtocolLib.jar/com.comphenix.protocol.injector.netty.channel.NettyChannelProxy.writeAndFlush(NettyChannelProxy.java:227) ~[ProtocolLib.jar:?] at ProtocolLib.jar/com.comphenix.protocol.injector.netty.channel.NettyChannelProxy.writeAndFlush(NettyChannelProxy.java:233) ~[ProtocolLib.jar:?] at net.minecraft.network.Connection.doSendPacket(Connection.java:513) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.Connection.lambda$sendPacket$13(Connection.java:498) ~[paper-1.21.jar:1.21-47-62ed302] at ProtocolLib.jar/com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.lambda$proxyRunnable$2(NettyEventLoopProxy.java:48) ~[ProtocolLib.jar:?] 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 java.lang.Object cannot be cast to class net.minecraft.network.chat.numbers.NumberFormat (java.lang.Object is in module java.base of loader 'bootstrap'; net.minecraft.network.chat.numbers.NumberFormat is in unnamed module of loader java.net.URLClassLoader @290d210d) at net.minecraft.network.codec.StreamCodec$6.encode(StreamCodec.java:104) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.codec.ByteBufCodecs$18.encode(ByteBufCodecs.java:363) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.codec.ByteBufCodecs$18.encode(ByteBufCodecs.java:353) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.protocol.game.ClientboundSetObjectivePacket.write(ClientboundSetObjectivePacket.java:57) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.codec.StreamCodec$2.encode(StreamCodec.java:38) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:88) ~[paper-1.21.jar:1.21-47-62ed302] at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:78) ~[paper-1.21.jar:1.21-47-62ed302] ... 39 more

I understand that you cannot cast the java.lang.Object class to net.minecraft.network.chat.numbers.NumberFormat. But I do not know how to do it. I tried debugging the Optional field, but there are no values ​​there and I can't change anything.

Please help me, I've been trying to solve it myself for two days, but I don't have time anymore.

commented

The package contains all the default implementations of NumberFormat: StyledFormat, FixedFormat, and BlankFormat. For more information on how they work, please refer to their source code. The packet you're trying to modify is the following: net.minecraft.network.protocol.game.ClientboundSetObjectivePacket

Regarding the packet not containing any boolean fields, it's important to note that wiki.vg outlines only the data transmitted over the network. It does not describe the actual implementation of the packet in the Minecraft server. Therefore, you should also examine the server's source code and use wiki.vg as a general guide.