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

Color problem in console for Bukkit.broadcast() #7590

Closed
x9nico opened this issue Mar 13, 2022 · 5 comments
Closed

Color problem in console for Bukkit.broadcast() #7590

x9nico opened this issue Mar 13, 2022 · 5 comments
Labels
resolution: works as intended Working as it should / expected to type: bug Something doesn't work as it was intended to.

Comments

@x9nico
Copy link

x9nico commented Mar 13, 2022

Expected behavior

It should set in colors my broadcasts. There, it don't want to set the colors in console

Observed/Actual behavior

image
image

Steps/models to reproduce

Make a broadcast in your code, like this:
Bukkit.broadcast(Component.text(PvPBoxPlugin.getInstance().getConfig().getString("reset_map_announce").replace("&", "§").replace("{time}", Integer.toString(time))));

Plugin and Datapack List

image
PvPBox is a custom plugin

Paper version

[16:30:54 INFO]: This server is running Paper version git-Paper-247 (MC: 1.18.2) (Implementing API version 1.18.2-R0.1-SNAPSHOT) (Git: 1358d1e)
You are running the latest version
Previous version: git-Paper-232 (MC: 1.18.2)

Other

It does that bug from I updated to build 247, it don't affect the 232.

No response

@x9nico x9nico added status: needs triage type: bug Something doesn't work as it was intended to. labels Mar 13, 2022
@NoahvdAa
Copy link
Member

NoahvdAa commented Mar 13, 2022

You should not mix adventure components and legacy formatting (§). Either deserialize your legacy messages using the LegacyComponentSerializer (or use minimessage instead of legacy), or use the legacy method, Bukkit#broadcastMessage. This will cause the proper behaviour, as shown below:

Bukkit.broadcast(Component.text("§cE")); // WRONG
Bukkit.broadcast(Component.text("E", NamedTextColor.RED));
Bukkit.broadcastMessage("§cE");

results in (e's without § are colored)

[17:11:36 INFO]: §cE
[17:11:36 INFO]: E
[17:11:36 INFO]: E

@x9nico
Copy link
Author

x9nico commented Mar 13, 2022

You should not mix adventure components and legacy formatting (§). Either deserialize your legacy messages using the LegacyComponentSerializer (or use minimessage instead of legacy), or use the legacy method, Bukkit#broadcastMessage. This will cause the proper behaviour, as shown below:

Bukkit.broadcast(Component.text("§cE")); // WRONG
Bukkit.broadcast(Component.text("E", NamedTextColor.RED));
Bukkit.broadcastMessage("§cE");

results in (e's without § are colored)

[17:11:36 INFO]: §cE
[17:11:36 INFO]: E
[17:11:36 INFO]: E

And how can I use NamedTextColor with the '&' ? It's in a config file for me :/

@electronicboy
Copy link
Member

you use the legacy component serialiser to deserialise a legacy string into a component if you wanna have components, or there is minimessage for a modern "rich" representation of components

@NoahvdAa
Copy link
Member

If you want to use legacy ampersands, the easiest solution would be to use the LegacyComponentSerializer like this:

Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize("&cMy message here"));

or, you could use minimessage instead:

Bukkit.broadcast(MiniMessage.miniMessage().deserialize("<red>My message here"));

🥷 ninja'd by cat

@x9nico
Copy link
Author

x9nico commented Mar 13, 2022

If you want to use legacy ampersands, the easiest solution would be to use the LegacyComponentSerializer like this:

Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize("&cMy message here"));

or, you could use minimessage instead:

Bukkit.broadcast(MiniMessage.miniMessage().deserialize("<red>My message here"));

🥷 ninja'd by cat

It works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution: works as intended Working as it should / expected to type: bug Something doesn't work as it was intended to.
Projects
None yet
Development

No branches or pull requests

4 participants