Open LaserSlime opened 3 years ago
For 2., Can't you just use ComponentBuilder? You should always be using ComponentBuilder rather than individually making components.
For 2., Can't you just use ComponentBuilder? You should always be using ComponentBuilder rather than individually making components.
Yes, but ComponentBuilder returns a BaseComponent[] which I can't use in MOTD's. The only way to get around this would be to create a TextComponent() and pass the BaseComponent[] as a parameter (As suggested in https://www.spigotmc.org/threads/rgb-colored-motd-using-componentbuilder.503842/#post-4167435), which like I said is really messy and shouldn't be necessary.
Probably ComponentBuilder needs a .buildSingle method, but ultimately it would just internally do what you call 'messy' which is correct.
Can't you just add a method that accepts a BaseComponent[] for setting the server motd?
Can't you just add a method that accepts a BaseComponent[] for setting the server motd?
Not unless the Mojang client supports that, which given the method was never added in the first place, it likely doesn't.
Hey, I would like to add a question to this.
With legacy text this would work with hex code:
player.sendMessage(text.replaceAll("&", "§"));
but not with a TextComponent:
player.sendMessage(new TextComponent(text.replaceAll("&", "§")));
This raises the question of why TextComponent does not support Hex-code? It wouldn't be the best solution, but it would be one way of dealing with it.
Because that's a common pitfall https://www.spigotmc.org/wiki/the-chat-component-api/#common-pitfalls
You need to use a component builder and fromlegacy
The TextComponent(String text) constructor only works with regular color codes, but not with rgb color codes like TextComponent.fromLegacyText() does.
TextComponent component = new TextComponent("test"); component.setColor(ChatColor.of(new Color(0x69420))); ping.setDescriptionComponent(new TextComponent(component.toLegacyText()));
I know this code is weird. It's only for demonstration. The message sent to the player will be black instead of green. The problem with using TextComponent.fromLegacyText() is that it returns a BaseComponent[] which can't be used in for example MOTD's. To fix that I would need to put it in another TextComponent constructor which looks really messy.
TextComponent component = new TextComponent("test"); component.setColor(ChatColor.of(new Color(0x69420))); ping.setDescriptionComponent(new TextComponent(TextComponent.fromLegacyText(component.toLegacyText())));
Again, I know this code doesn't make any sense, It's just for demonstration. I need to do this since I want to automatically center my motd and I need to know which characters are bold and I can only do that with legacy text (As far as I'm aware), but I don't want to use the legacy text methods since they are deprecated and might get removed in the future.
There are two ways to fix this problem: