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

Serializes lose hoverEvent between Json -> Component conversions and vice versa #1025

Open
LoneDev6 opened this issue Jan 3, 2024 · 5 comments

Comments

@LoneDev6
Copy link

LoneDev6 commented Jan 3, 2024

For some reason serializes lose hoverEvent between Json -> Component conversions and vice versa.

Server version: 1.19.4.
Current: git-Purpur-1985 (MC: 1.19.4)

        <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>

My code:

GsonComponentSerializer.gson().serialize(
        GsonComponentSerializer.gson().deserialize(jsonString)
);

Second attempt specifying legacy hover serializer (same result).

GsonComponentSerializer gson = GsonComponentSerializer.builder()
                .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get())
                .options(
                        OptionState.optionState()
                                .value(JSONOptions.EMIT_RGB, Boolean.TRUE)
                                .value(JSONOptions.EMIT_HOVER_EVENT_TYPE, JSONOptions.HoverEventValueMode.BOTH)
                                .value(JSONOptions.EMIT_COMPACT_TEXT_COMPONENT, Boolean.TRUE)
                                .value(JSONOptions.EMIT_HOVER_SHOW_ENTITY_ID_AS_INT_ARRAY, Boolean.FALSE)
                                .value(JSONOptions.VALIDATE_STRICT_EVENTS, Boolean.FALSE)
                                .build()
                )
                .build();;
        String bro = gson.serialize(
                gson.deserialize(buggedJsonStr)
        );

This component was obtained from another plugin called ChatControlRed.

Before

{
  "extra": [
    {
      "hoverEvent": {
        "action": "show_text",
        "value": [
          {
            "extra": [
              {
                "text": "flpm_9eeed723-306e-44c0-9bb9-0c138a9e2f9a flps_68bbf558-ed0e-37ab-bb3e-9c8672097642"
              }
            ],
            "text": ""
          }
        ]
      },
      "text": ""
    },
    {
      "extra": [
        { "color": "dark_gray", "text": "[" },
        { "color": "dark_red", "text": "admin" },
        { "color": "dark_gray", "text": "] " },
        { "color": "white", "text": "LoneDev" },
        { "color": "gray", "text": ": " },
        { "color": "white", "text": "" }
      ],
      "text": ""
    },
    {
      "extra": [
        {
          "color": "gray",
          "hoverEvent": {
            "action": "show_item",
            "value": [{ "text": "{Count:59b,id:\"minecraft:stone\"}" }]
          },
          "text": "["
        },
        {
          "color": "yellow",
          "hoverEvent": {
            "action": "show_item",
            "value": [{ "text": "{Count:59b,id:\"minecraft:stone\"}" }]
          },
          "text": "59x "
        },
        {
          "color": "white",
          "hoverEvent": {
            "action": "show_item",
            "value": [{ "text": "{Count:59b,id:\"minecraft:stone\"}" }]
          },
          "text": "Stone"
        },
        {
          "color": "gray",
          "hoverEvent": {
            "action": "show_item",
            "value": [{ "text": "{Count:59b,id:\"minecraft:stone\"}" }]
          },
          "text": "]"
        }
      ],
      "text": ""
    }
  ],
  "text": ""
}

After

{
  "extra": [
    {
      "hoverEvent": {
        "action": "show_text",
        "contents": {
          "extra": [
            "flpm_9eeed723-306e-44c0-9bb9-0c138a9e2f9a flps_68bbf558-ed0e-37ab-bb3e-9c8672097642"
          ],
          "text": ""
        }
      },
      "text": ""
    },
    {
      "extra": [
        { "color": "dark_gray", "text": "[" },
        { "color": "dark_red", "text": "admin" },
        { "color": "dark_gray", "text": "] " },
        { "color": "white", "text": "LoneDev" },
        { "color": "gray", "text": ": " },
        { "color": "white", "text": "" }
      ],
      "text": ""
    },
    {
      "extra": [
        { "color": "gray", "text": "[" },
        { "color": "yellow", "text": "59x " },
        { "color": "white", "text": "Stone" },
        { "color": "gray", "text": "]" }
      ],
      "text": ""
    }
  ],
  "text": ""
}
@LoneDev6
Copy link
Author

LoneDev6 commented Jan 4, 2024

This doesn't lose any data, so the issue is probably caused by the "value" tag, I think.
The issue might be caused by the fact that some plugins are sending legacy hover events data and for some reason Adventure is discarding them.

{
  "extra": [
    { "color": "gold", "text": "LoneDev's item is " },
    { "color": "gold", "text": "" },
    { "color": "gold", "text": "" },
    {
      "color": "white",
      "hoverEvent": {
        "action": "show_item",
        "contents": { "id": "minecraft:wooden_axe", "tag": "{Damage:10}" }
      },
      "text": "Wooden Axe x1"
    }
  ],
  "text": ""
}

@LoneDev6 LoneDev6 changed the title Serializes lose nested hoverEvent between Json -> Component conversions and vice versa Serializes lose hoverEvent between Json -> Component conversions and vice versa Jan 4, 2024
@zml2008
Copy link
Member

zml2008 commented Jan 4, 2024

What happens when you enable validating strict events, rather than telling the serializer to silently discard any useful information for this issue

(also you seem to have done part of your process incorrectly inserting legacy characters in your components, we'd recommend fixing that to avoid inconsistent styling)

@LoneDev6
Copy link
Author

LoneDev6 commented Jan 4, 2024

Thanks!
I'd expect the adventure API to allow legacy components as the client shows these messages correctly even on modern versions.
I am not the author of the other plugin so I have no control over their malformed JSON, but the client accepts it so I guess adventure should also do that.

Let me know what you think, thanks.

@MiniDigger
Copy link
Member

mojang says to not use it, as such adventure doesn't support (and in some cases even block) legacy formatting characters
https://bugs.mojang.com/browse/MC-190605?focusedId=993040#comment-993040

@LoneDev6
Copy link
Author

LoneDev6 commented Jan 5, 2024

It's not about § legacy colors, it's about the legacy way to create hover events.
I edited the message to avoid confusion: #1025 (comment)

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

3 participants