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

Parsing of json fails if item data component removal syntax is used (e.g. !minecraft:enchantments in Wind Charge books from Trial Spawners) #1131

Open
Phoenix616 opened this issue Nov 19, 2024 · 0 comments

Comments

@Phoenix616
Copy link

Phoenix616 commented Nov 19, 2024

When trying to parse a json component that includes a key that uses the item data component removal syntax in a hover item specification with a exclamation mark in front of the key (e.g. !minecraft:enchantments in Wind Charge books from Trial Spawners, this is not set on Creative items!) an exception is thrown: Non [a-z0-9_.-] character in namespace of Key[!minecraft:enchantments] at index 0 ('e', bytes: [101])

A full stacktrace using adventure 4.17.0

de.themoep.ShowItem.libs.kyori.adventure.key.InvalidKeyException: Non [a-z0-9_.-] character in namespace of Key[!minecraft:enchantments] at index 0 ('e', bytes: [101])
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.key.KeyImpl.checkError(KeyImpl.java:58) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.key.KeyImpl.<init>(KeyImpl.java:48) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.key.Key.key(Key.java:137) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.key.Key.key(Key.java:111) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.key.Key.key(Key.java:88) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.text.serializer.gson.ShowItemSerializer.read(ShowItemSerializer.java:97) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.text.serializer.gson.ShowItemSerializer.read(ShowItemSerializer.java:49) ~[ShowItem.jar:?]
	at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:204) ~[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 ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.text.serializer.gson.StyleSerializer.read(StyleSerializer.java:180) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.text.serializer.gson.StyleSerializer.read(StyleSerializer.java:62) ~[ShowItem.jar:?]
	at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:204) ~[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 ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.text.serializer.gson.ComponentSerializerImpl.read(ComponentSerializerImpl.java:224) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.text.serializer.gson.ComponentSerializerImpl.read(ComponentSerializerImpl.java:77) ~[ShowItem.jar:?]
	at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:204) ~[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:1137) ~[gson-2.10.1.jar:?]
	at com.google.gson.Gson.fromJson(Gson.java:1047) ~[gson-2.10.1.jar:?]
	at com.google.gson.Gson.fromJson(Gson.java:982) ~[gson-2.10.1.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializerImpl.deserialize(GsonComponentSerializerImpl.java:89) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializerImpl.deserialize(GsonComponentSerializerImpl.java:41) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.ItemConverterImplementation.lambda$new$0(ItemConverterImplementation.java:127) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.ItemConverterImplementation.getHoverEvent(ItemConverterImplementation.java:229) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.ItemConverterImplementation.access$100(ItemConverterImplementation.java:56) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.ItemConverterImplementation$ComponentImplementation.<init>(ItemConverterImplementation.java:330) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.ItemConverterImplementation$ComponentImplementation.<init>(ItemConverterImplementation.java:310) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.ItemConverterImplementation.createComponent(ItemConverterImplementation.java:222) ~[ShowItem.jar:?]
	at ShowItem.jar/de.themoep.ShowItem.HelpMessenger.onClick(HelpMessenger.java:168) ~[ShowItem.jar:?]
	at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor176.execute(Unknown Source) ~[?:?]
	at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?]
	at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:84) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:1.21.1-131-84281ce]
	at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?]
	at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:54) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:131) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:628) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.handleContainerClick(ServerGamePacketListenerImpl.java:3224) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.network.protocol.game.ServerboundContainerClickPacket.handle(ServerboundContainerClickPacket.java:69) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.network.protocol.game.ServerboundContainerClickPacket.handle(ServerboundContainerClickPacket.java:33) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:56) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:151) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1535) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:201) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:125) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1512) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1505) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:135) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.server.MinecraftServer.managedBlock(MinecraftServer.java:1464) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1471) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1316) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:329) ~[paper-1.21.1.jar:1.21.1-131-84281ce]
	at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]

More context for this particular error: https://gitlab.com/Phoenix616/ShowItem/-/issues/21

In this plugin the json that is parsed via Adventure is obtained directly from NMS via Component.empty().withStyle((chatmodifier) -> chatmodifier.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackInfo(nmsItem)))) and serializing that to JSON (all classes are NMS classes) but I strongly suspect that the same issue occurs when using Paper's API implementation.

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

No branches or pull requests

1 participant