horsewithnoname Posted October 28, 2016 Posted October 28, 2016 Hello there! I stumbled across this issue, where messages formatted incorrectly when using TextComponentTranslation with formatting. See this screenshot: Message "Director block at (-580..." breaks the formatting after an argument gets replaced. The same thing happens to "The director block, that was attached..." label, however it has additional formatting, because the numbers should be colored in dark red. Both of those strings are look like this in en_US.lang: blockbuster.success.director.play=§aDirector block at (%s, %s, %s) has started playing! blockbuster.error.director.missing=§cThe director block, that was attached to this device at (§4%s§c, §4%s§c, §4%s§c), was destroyed or moved. Attach this device to another director block! And they're both sent this way (on the server): /* Director block at ... */ sender.addChatMessage(new TextComponentTranslation("blockbuster.success.director.play", args[1], args[2], args[3])); /* The director block, that was attached... */ player.addChatMessage(new TextComponentTranslation("blockbuster.error.director.missing", pos.getX(), pos.getY(), pos.getZ())); However, you as you can see also on the screenshot, there's another error message that says "Morph by name ..." colors correctly. This one, actually, sent from client side (client side command) this way: sender.addChatMessage(new TextComponentString(I18n.format("blockbuster.success.morph.enable", args[0]))); And now is the question. Is there a way to avoid formatting reset when specifying arguments to TextComponentTranslation without much hassle like creating ITextComponent for every argument with its own formatting (thus hardcoding color formatting)? I know that I can use the TextComponentString + I18n.format, but will it work on dedicated server? Thank you for attention! Quote Blockbuster – simple machinimas and cinematics for Minecraft
horsewithnoname Posted October 29, 2016 Author Posted October 29, 2016 I think you'll have to wrap the arguments in a ITextComponent manually, then the style will be applied to them as well. I wish there was another way... Thanks for the answer! Quote Blockbuster – simple machinimas and cinematics for Minecraft
horsewithnoname Posted October 30, 2016 Author Posted October 30, 2016 I actually come up with another solution. Instead of wrapping every argument into ITextComponent, I create the parent ITextComponent with desired color for arguments, and then reset the color to my original color for the string, and I get what I wanted: com.example.string=§aGreen label with a dark green %s§a meme! And initiate the message like that: String key = "com.example.string"; ITextComponent text = new TextComponentTranslation(key, "dank"); text.getStyle().setColor(TextFormatting.DARK_GREEN); sender.addChatMessage(text); Quote Blockbuster – simple machinimas and cinematics for Minecraft
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.