CraftChatMessage#fromComponent misrepresenting components

XMLWordPrintable

    • 1.20.2
    • Yes

      While this is already possible through simple ingame commands, spigot also has a PR lined up to finally bring more component support to places in the API.

      While the legacy text format is still in heavy usage across the spigot API, it cannot fully represent components, which is fine for most usecase where only text and colouring/styling is applied.
      Its inability to represent components however quickly becomes a problem when interacting with e.g. ItemStacks that are created without the usage of legacy text but instead via commands or, in the future, via component API. It is hence crucial that, when possible, the legacy format represents the styling of components as well as possible to minimise the loss of information.

      One such issue arises terrible quickly when creating components that make use of inherited styling in a nested component tree, such as the following:

      {
         "text":"top",
         "color":"red",
         "extra":[
            {
               "text":" mid ",
               "color":"blue"
            },
            {
               "text":" inherit"
            }
         ]
      }
      

      which leads to the following item display in-game:

      as the second child inherits the red colouring of its parent while the first overwrites it to blue.

      Passing this component into CraftChatMessage#fromComponent however yields a completely unusable legacy string of 

      §ctop§9 mid§r inherit
      

      leaving inherit completely uncoloured. This is mostly related to the fact that CraftChatMessage#fromComponent does not respect the tree like layout of components but rather simply uses their flattened representation.

      This issue asks for improved handling of these cases, e.g. the above example should be resolved to

      §ctop§9 mid§c inherit 

      which allows the legacy format to represent the component as best as possible in the context of its limited nature.

            Assignee:
            Unassigned
            Reporter:
            Bjarne Koll
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: