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

Style decorations are lost after Modifying tags are applied #790

Closed
metabrixkt opened this issue Jun 23, 2022 · 1 comment · Fixed by #835
Closed

Style decorations are lost after Modifying tags are applied #790

metabrixkt opened this issue Jun 23, 2022 · 1 comment · Fixed by #835

Comments

@metabrixkt
Copy link

Input

<gradient>This <italic>is</italic> a <bold>test</bold>!</gradient>

Expected output

JSON
{
    "extra": [
        {
            "color": "white",
            "text": "T"
        },
        {
            "color": "#eeeeee",
            "text": "h"
        },
        {
            "color": "#dddddd",
            "text": "i"
        },
        {
            "color": "#cccccc",
            "text": "s"
        },
        {
            "color": "#bbbbbb",
            "text": " "
        },
        {
            "italic": true,
            "extra": [
                {
                    "color": "gray",
                    "text": "i"
                },
                {
                    "color": "#999999",
                    "text": "s"
                }
            ],
            "text": ""
        },
        {
            "color": "#888888",
            "text": " "
        },
        {
            "color": "#777777",
            "text": "a"
        },
        {
            "color": "#666666",
            "text": " "
        },
        {
            "bold": true,
            "extra": [
                {
                    "color": "dark_gray",
                    "text": "t"
                },
                {
                    "color": "#444444",
                    "text": "e"
                },
                {
                    "color": "#333333",
                    "text": "s"
                },
                {
                    "color": "#222222",
                    "text": "t"
                }
            ],
            "text": ""
        },
        {
            "color": "#111111",
            "text": "!"
        }
    ],
    "text": ""
}

image

Actual (observed) output

JSON
{
    "extra": [
        {
            "color": "white",
            "text": "T"
        },
        {
            "color": "#eeeeee",
            "text": "h"
        },
        {
            "color": "#dddddd",
            "text": "i"
        },
        {
            "color": "#cccccc",
            "text": "s"
        },
        {
            "color": "#bbbbbb",
            "text": " "
        },
        {
            "color": "gray",
            "text": "i"
        },
        {
            "color": "#999999",
            "text": "s"
        },
        {
            "color": "#888888",
            "text": " "
        },
        {
            "color": "#777777",
            "text": "a"
        },
        {
            "color": "#666666",
            "text": " "
        },
        {
            "color": "dark_gray",
            "text": "t"
        },
        {
            "color": "#444444",
            "text": "e"
        },
        {
            "color": "#333333",
            "text": "s"
        },
        {
            "color": "#222222",
            "text": "t"
        },
        {
            "color": "#111111",
            "text": "!"
        }
    ],
    "text": ""
}

image

Other information

Version: 4.11.0 (also reproduced at 167e46d which is 4.12.0-SNAPSHOT)

I had some troubles reproducing this sometimes. First time when I found this bug, I was using this code:

Gson gson = new GsonBuilder().setPrettyPrinting().create();
Component component = Component.text("20");
System.out.println("component = " + gson.toJson(GsonComponentSerializer.gson().serializeToTree(component)));
Component customName = event.isCritical()
        ? MiniMessage.miniMessage().deserialize(
        "<gradient:#FFAA00:#FF5555><component></gradient>",
        Placeholder.component("component", component.append(Component.text("✧").decorate(TextDecoration.BOLD)))
) : component;
System.out.println("customName = " + gson.toJson(GsonComponentSerializer.gson().serializeToTree(customName)));

and got this output:

[14:14:39 INFO]: [STDOUT] component = {
  "extra": [
    {
      "bold": true,
      "text": "✧"
    }
  ],
  "text": "20"
}
[14:14:39 INFO]: [STDOUT] customName = {
  "extra": [
    {
      "color": "gold",
      "text": "2"
    },
    {
      "color": "#ff8e1c",
      "text": "0"
    },
    {
      "color": "#ff7139",
      "text": "✧"
    }
  ],
  "text": ""
}

I found that here at line 121 new Component is created with this.color() instead of textComponent.style().color(this.color()) as a second argument, thus styles are lost.

After some debugging I found that text components with is and test contents that are being sent to apply(Component, int) method, are actually {"italic": true, "text": "", "extra": [{"text": "is"}]} and {"bold": true, "text": "", "extra": [{"text": "test"}]} after inner italic and bold tags are applied. Inner {"text": "is"} and {"text": "test"} don't have styles at all, so nothing would be applied even with the fix I described in the previous paragraph.

@zml2008
Copy link
Member

zml2008 commented Nov 7, 2022

Thanks for your thorough investigation! Seems like this is an issue that comes up when you use component placeholders -- internally MM doesn't have multiple style elements on one tag, but I believe your fix should work.

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

Successfully merging a pull request may close this issue.

2 participants