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

Issue with Translator-rendering when not closing </lang> tag #974

Open
Boy0000 opened this issue Sep 20, 2023 · 0 comments
Open

Issue with Translator-rendering when not closing </lang> tag #974

Boy0000 opened this issue Sep 20, 2023 · 0 comments

Comments

@Boy0000
Copy link

Boy0000 commented Sep 20, 2023

This builds upon #972 but could replicate this with other similar implementations.
In short, when using a Translator as a source to GlobalTranslator that formats a minimessage string from a given translation-key, it breaks when not fully closing lang-tag.
It seems to just clear any sort of tags after a first one, like the gradient dissapearing below and the following text
Ofc also means all following lang-keys are not formatted

image

Discord convo

Below is some code to more easily reproduce this
then just run the /example command iguess with the config containing example.key.value and value2 with some form of MM message after:

import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.translation.GlobalTranslator;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class Plugin extends JavaPlugin {
    
    private static Plugin instance;
    
    @Override
    public void onEnable() {
        saveDefaultConfig();
        instance = this;

        GlobalTranslator.translator().addSource(new Translator());
        getCommand("example").setExecutor(new Command());
    }
    
    private class Command implements CommandExecutor {
        @Override
        public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
            if (Objects.equals(label, "example")) {
                sender.sendMessage(GlobalTranslator.render(MiniMessage.miniMessage().deserialize("<lang:example.key.value><lang:example.key.value2>");
                sender.sendMessage(GlobalTranslator.render(MiniMessage.miniMessage().deserialize("<lang:example.key.value></lang><lang:example.key.value2>");
            }
            return true;
        }
    }
    
    public static Plugin getInstance() {
        return instance;
    }
    
}
public class Translator extends MiniMessageTranslator {
    @Nullable
    @Override
    protected String getMiniMessageString(@NotNull String key, @NotNull Locale locale) {
        return Plugin.getInstance().getConfig().getString(key);
    }

    @Override
    public @NotNull Key name() {
        return Key.key("example", "translator");
    }
}
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

1 participant