Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinecraftComponentSerializer throws UnsupportedOperationException #150

Open
LoneDev6 opened this issue Jan 3, 2024 · 2 comments · May be fixed by #197
Open

MinecraftComponentSerializer throws UnsupportedOperationException #150

LoneDev6 opened this issue Jan 3, 2024 · 2 comments · May be fixed by #197

Comments

@LoneDev6
Copy link

LoneDev6 commented Jan 3, 2024

Tested on:

  • 1.19.4
  • 1.20.2
  • 1.20.4

I get UnsupportedOperationException when calling MinecraftComponentSerializer.get().serialize(component); on villagers names trade GUI name and some other texts.

Only way to fix that is to convert the adventure Component to Json String and use NMS to convert the Json String to Minecraft MutableComponent, I tried that and works fine.
Seems the issue is somehow caused by the json tree -> MutableComponent implementation.

        <dependency>
            <groupId>net.kyori</groupId>
            <artifactId>adventure-api</artifactId>
            <version>4.15.0</version>
        </dependency>
        <dependency>
            <groupId>net.kyori</groupId>
            <artifactId>adventure-text-serializer-gson</artifactId>
            <version>4.15.0</version>
        </dependency>
        <dependency>
            <groupId>net.kyori</groupId>
            <artifactId>adventure-text-serializer-gson-legacy-impl</artifactId>
            <version>4.15.0</version>
        </dependency>
        <dependency>
            <groupId>net.kyori</groupId>
            <artifactId>adventure-platform-bukkit</artifactId>
            <version>4.3.2</version>
        </dependency>
        <dependency>
            <groupId>net.kyori</groupId>
            <artifactId>adventure-text-minimessage</artifactId>
            <version>4.15.0</version>
        </dependency>
[15:02:10 ERROR]: [ItemsAdder] Unhandled exception occurred in onPacketSending(PacketEvent) for ItemsAdder
java.lang.UnsupportedOperationException: com.google.gson.JsonSyntaxException: Expected id to be a string, was an array ([140...38])
	at net.kyori.adventure.platform.bukkit.MinecraftComponentSerializer.serialize(MinecraftComponentSerializer.java:225) ~[LoneLibs.jar:?]
	at ia.m.iI.a(SourceFile:97) ~[ItemsAdder_3.6.3-beta-5.jar:?]
	at ia.m.hy.onPacketSending(SourceFile:173) ~[ItemsAdder_3.6.3-beta-5.jar:?]
	at com.comphenix.protocol.injector.SortedPacketListenerList.invokeSendingListener(SortedPacketListenerList.java:219) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.SortedPacketListenerList.invokeUnpackedPacketSending(SortedPacketListenerList.java:204) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketSending(SortedPacketListenerList.java:149) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketSending(SortedPacketListenerList.java:139) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.PacketFilterManager.postPacketToListeners(PacketFilterManager.java:553) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.PacketFilterManager.invokePacketSending(PacketFilterManager.java:526) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.netty.manager.NetworkManagerInjector.onPacketSending(NetworkManagerInjector.java:100) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.netty.channel.NettyChannelInjector.processOutbound(NettyChannelInjector.java:553) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.netty.channel.NettyChannelInjector$2.doProxyRunnable(NettyChannelInjector.java:456) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.proxyRunnable(NettyEventLoopProxy.java:43) ~[ProtocolLib.jar:?]
	at com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.execute(NettyEventLoopProxy.java:252) ~[ProtocolLib.jar:?]
	at net.minecraft.network.Connection.sendPacket(Connection.java:432) ~[?:?]
	at net.minecraft.network.Connection.send(Connection.java:392) ~[?:?]
	at net.minecraft.server.network.ServerCommonPacketListenerImpl.send(ServerCommonPacketListenerImpl.java:276) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at net.minecraft.server.network.ServerCommonPacketListenerImpl.send(ServerCommonPacketListenerImpl.java:261) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at net.minecraft.server.level.ServerPlayer.openMenu(ServerPlayer.java:1640) ~[?:?]
	at net.minecraft.world.item.trading.Merchant.openTradingScreen(Merchant.java:41) ~[?:?]
	at net.minecraft.world.entity.npc.Villager.startTrading(Villager.java:453) ~[?:?]
	at net.minecraft.world.entity.npc.Villager.mobInteract(Villager.java:431) ~[?:?]
	at net.minecraft.world.entity.Mob.interact(Mob.java:1374) ~[?:?]
	at net.minecraft.world.entity.player.Player.interactOn(Player.java:1174) ~[?:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl$4.performInteraction(ServerGamePacketListenerImpl.java:2816) ~[?:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl$4.a(ServerGamePacketListenerImpl.java:2836) ~[?:?]
	at net.minecraft.network.protocol.game.ServerboundInteractPacket$InteractionAction.dispatch(ServerboundInteractPacket.java:131) ~[?:?]
	at net.minecraft.network.protocol.game.ServerboundInteractPacket.dispatch(ServerboundInteractPacket.java:80) ~[?:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.handleInteract(ServerGamePacketListenerImpl.java:2775) ~[?:?]
	at net.minecraft.network.protocol.game.ServerboundInteractPacket.handle(ServerboundInteractPacket.java:67) ~[?:?]
	at net.minecraft.network.protocol.game.ServerboundInteractPacket.handle(ServerboundInteractPacket.java:12) ~[?:?]
	at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:53) ~[?:?]
	at net.minecraft.server.TickTask.run(TickTask.java:18) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
	at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1351) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:193) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
	at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1328) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1321) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
	at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1299) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1187) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320) ~[purpur-1.20.2.jar:git-Purpur-2095]
	at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: com.google.gson.JsonSyntaxException: Expected id to be a string, was an array ([140...38])
	at net.minecraft.util.GsonHelper.convertToString(GsonHelper.java:97) ~[?:?]
	at net.minecraft.util.GsonHelper.getAsString(GsonHelper.java:103) ~[?:?]
	at net.minecraft.network.chat.HoverEvent$EntityTooltipInfo.create(HoverEvent.java:177) ~[?:?]
	at net.minecraft.network.chat.HoverEvent$Action.deserialize(HoverEvent.java:136) ~[?:?]
	at net.minecraft.network.chat.HoverEvent.deserialize(HoverEvent.java:80) ~[?:?]
	at net.minecraft.network.chat.Style$Serializer.getHoverEvent(Style.java:405) ~[?:?]
	at net.minecraft.network.chat.Style$Serializer.deserialize(Style.java:377) ~[?:?]
	at net.minecraft.network.chat.Style$Serializer.deserialize(Style.java:364) ~[?:?]
	at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:76) ~[gson-2.10.1.jar:?]
	at com.google.gson.Gson.fromJson(Gson.java:1227) ~[gson-2.10.1.jar:?]
	at com.google.gson.Gson.fromJson(Gson.java:1329) ~[gson-2.10.1.jar:?]
	at com.google.gson.Gson.fromJson(Gson.java:1300) ~[gson-2.10.1.jar:?]
	at com.google.gson.internal.bind.TreeTypeAdapter$GsonContextImpl.deserialize(TreeTypeAdapter.java:179) ~[gson-2.10.1.jar:?]
	at net.minecraft.network.chat.Component$Serializer.deserialize(Component.java:361) ~[?:?]
	at net.minecraft.network.chat.Component$Serializer.deserialize(Component.java:222) ~[?:?]
	at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:76) ~[gson-2.10.1.jar:?]
	at com.google.gson.Gson.fromJson(Gson.java:1227) ~[gson-2.10.1.jar:?]
	at com.google.gson.Gson.fromJson(Gson.java:1329) ~[gson-2.10.1.jar:?]
	at com.google.gson.Gson.fromJson(Gson.java:1271) ~[gson-2.10.1.jar:?]
	at net.minecraft.network.chat.Component$Serializer.fromJson(Component.java:536) ~[?:?]
	at net.kyori.adventure.platform.bukkit.MinecraftComponentSerializer.serialize(MinecraftComponentSerializer.java:221) ~[LoneLibs.jar:?]
	... 44 more
[15:02:10 ERROR]: Parameters: 
  net.minecraft.network.protocol.game.PacketPlayOutOpenWindow@2d1a960d[
    a=11
    b=net.minecraft.world.inventory.Containers@3a73661d
    c=translation{key='entity.minecraft.villager.farmer', args=[]}[style={hoverEvent=HoverEvent{action=<action show_entity>, value='net.minecraft.network.chat.ChatHoverable$b@8abdf856'},insertion=08629de5-8c47-4554-8ad5-1f075a194266}]
  ]
@Machine-Maker
Copy link
Member

For clarification, this also happens on 1.19.4 and 1.20.4? The stacktrace you provided is from 1.20.2 which is neither of those versions.

@LoneDev6
Copy link
Author

LoneDev6 commented Jan 3, 2024

This error was taken from a customer report, so you can also add 1.20.2 to the list of versions with the issue.

Here is the json:

{
  "insertion": "d9808418-fea1-480a-ba86-d6081693d626",
  "hoverEvent": {
    "action": "show_entity",
    "contents": {
      "type": "minecraft:villager",
      "id": [-645889000, -22984694, -1165568504, 378787366],
      "name": { "translate": "entity.minecraft.villager.farmer" }
    }
  },
  "translate": "entity.minecraft.villager.farmer"
}

It has to do with the fact that uuid (id) is a string in recent versions of the game and not an array, it seems.


Here is some information on what needs to be changed to fix that issue:
KyoriPowered/adventure#1015

The fix:
WiIIiam278/Velocity@dec36bd#diff-2856d6b2f881f52815f9efe35d7d3dd11a2e813ddd332cda3ecb7cd560a8821b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants