SpongePowered / Sponge

The SpongeAPI implementation targeting vanilla Minecraft and 3rd party platforms.
MIT License
390 stars 211 forks source link

TextTemplates seem to be horidly broken when saved #1814

Closed clienthax closed 11 months ago

clienthax commented 6 years ago

I am currently running

Issue Description

Saving TextTemplates to config seems to make them lose data or write the text completly wrong.

                unlockedVaultLore.add(TextTemplate.of(DARK_GRAY, STRIKETHROUGH, "                    "));
                unlockedVaultLore.add(TextTemplate.of(Text.EMPTY));
                unlockedVaultLore.add(TextTemplate.of(GOLD, "Space: ", WHITE, arg("usedSlots"), "/54"));
                unlockedVaultLore.add(TextTemplate.of(GOLD, "Empty Space: ", WHITE, arg("emptySpace")));
                unlockedVaultLore.add(TextTemplate.of(Text.EMPTY));
                unlockedVaultLore.add(TextTemplate.of(DARK_GRAY, "[", GOLD, "Left-Click Open", WHITE, " This Vault", DARK_GRAY, "]"));
                unlockedVaultLore.add(TextTemplate.of(DARK_GRAY, STRIKETHROUGH, "                    "));

produces this in config Seems most of the color references are missing etc..


    unlockedVaultLore=[
        {
            arguments {}
            content {
                color="dark_gray"
                extra=[
                    {
                        text="                    "
                    }
                ]
                strikethrough=true
                text=""
            }
            options {
                closeArg="}"
                openArg="{"
            }
        },
        {
            arguments {}
            content {
                text=""
            }
            options {
                closeArg="}"
                openArg="{"
            }
        },
        {
            arguments {
                usedSlots {
                    optional=false
                }
            }
            content {
                color=white
                extra=[
                    {
                        text="Space: "
                    },
                    {
                        text="{usedSlots}"
                    },
                    {
                        text="/54"
                    }
                ]
                text=""
            }
            options {
                closeArg="}"
                openArg="{"
            }
        },
        {
            arguments {
                emptySpace {
                    optional=false
                }
            }
            content {
                color=white
                extra=[
                    {
                        text="Empty Space: "
                    },
                    {
                        text="{emptySpace}"
                    }
                ]
                text=""
            }
            options {
                closeArg="}"
                openArg="{"
            }
        },
        {
            arguments {}
            content {
                text=""
            }
            options {
                closeArg="}"
                openArg="{"
            }
        },
        {
            arguments {}
            content {
                color="dark_gray"
                extra=[
                    {
                        text="["
                    },
                    {
                        text="Left-Click Open"
                    },
                    {
                        text=" This Vault"
                    },
                    {
                        text="]"
                    }
                ]
                text=""
            }
            options {
                closeArg="}"
                openArg="{"
            }
        },
        {
            arguments {}
            content {
                color="dark_gray"
                extra=[
                    {
                        text="                    "
                    }
                ]
                strikethrough=true
                text=""
            }
            options {
                closeArg="}"
                openArg="{"
            }
        }
    ]
    "unnamed_vault" {
        arguments {
            vaultNumber {
                optional=false
            }
        }
        content {
            color="dark_gray"
            extra=[
                {
                    text="["
                },
                {
                    text="Vault "
                },
                {
                    text="#"
                },
                {
                    text="{vaultNumber}"
                },
                {
                    text="]"
                }
            ]
            text=""
        }
        options {
            closeArg="}"
            openArg="{"
        }
    }
Eufranio commented 6 years ago

Not sure what happened, but this:

        @Setting
        public TextTemplate NAME = TextTemplate.of(
                TextColors.AQUA, "Name: ", TextColors.GREEN, TextTemplate.arg("name")
        );

produced this:

        NAME {
            arguments {
                name {
                    optional=false
                }
            }
            closeArg="}"
            content {
                color=yellow
                extra=[
                    {
                        text="Name: "
                    },
                    {
                        text="{name}"
                    }
                ]
                text=""
            }
            openArg="{"
            options {
                closeArg="}"
                openArg="{"
            }
        }

(aqua text being saved as yellow)

Apparently, it only gets saved wrong if there are more than 1 color in the TextTemplate.

EDIT: Looks like this isn't like Text.of(), which builds the text with the args. TextTemplates only have ONE color, more colors should be added as new Text objects, like TextTemplate.of(TextColors.RED, "Hello ", Text.of(TextColors.AQUA, "world"));. Will open a issue on API.

randombyte-developer commented 6 years ago

May be related to #1152

ImMorpheus commented 11 months ago

Hey! You seem to be running an unsupported version (API 7) of SpongeAPI. Support for API 7 ended in January 2022.

API-7 is now end-of-life. We will not be issuing any more API updates for version 7 of our API^1

As part of our legacy cleanup we are closing issues relating to API7/1.12.2^2


The Text API is now supplied by the Kyori Adventure library so this issue is no longer relevant to this repository.