PorkStudios / PorkLib

Fast, lightweight libraries for Java. Note: this is very much a work-in-progress, documentation is spotty and the API is changing constantly!
https://daporkchop.net
Other
31 stars 5 forks source link

minecraft-text doesn't support translation components #53

Closed willemml closed 3 years ago

willemml commented 3 years ago

The minecraft-text library does not seem to parse chat messages in my "unmodded" (no plugins) Purpur (a Paper/Spigot/CraftBukkit fork), this may be due to the strange format it uses (note that everything useful is inside of "with"):

{"translate":"chat.type.text","with":[{"text":"wnuke","clickEvent":{"action":"suggest_command","value":"/tell wnuke "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"6eae0039-8396-3cb1-b63b-c6a62be747d9","name":"wnuke"}},"insertion":"wnuke"},"hello"]}

This is the Json given by the getOriginal() method, however toRawString() and getText() do not include the message ("hello"), they are empty/blank strings. However parsing works fine when I use the same server jar on a server using my custom chat plugin/mod which gives the following json:

{"text":"","extra":["<notfunnydidntask","> hello"]}

and gives the correct message "<notfunnydidntask> hello".

Same thing occurs with with /tell or /say messages, they work on the "modded" server but not on the "unmodded" server.

The code can be seen here.

DaMatrix commented 3 years ago

This isn't an issue with 1.16, it doesn't work because the library doesn't support translate components, as I didn't want to package a bunch of localization files with it. However, now that I think about it, it could very well be doable. I'll see about putting something together.

DaMatrix commented 3 years ago

You can now pass a TranslationSource to the constructor for JsonTextParser or AutoMCFormatParser (renamed from MCFormatParser) to provide translation keys.

Example (using your JSON string as reference): https://github.com/PorkStudios/PorkLib/blob/30040e5f67382d2a697eceff608eb6f309b953fd/minecraft/minecraft-text/src/example/java/FormattedPrintExample.java#L62 Result: result

Once Jenkins finishes compiling 30040e5f67382d2a697eceff608eb6f309b953fd, you can use it by refreshing your Maven/Gradle project (you may have to force update dependencies if your local repo cache is acting up)

willemml commented 3 years ago

This is awesome, I just tried it out, works great! Thanks a lot!