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

[Feature request] colorize() to support hex colors #1357

Closed
malonnnn opened this issue Apr 5, 2023 · 11 comments
Closed

[Feature request] colorize() to support hex colors #1357

malonnnn opened this issue Apr 5, 2023 · 11 comments
Labels
documentation good first issue Wanna take a stab at contributing? Try this one! Should be easier than most.

Comments

@malonnnn
Copy link

malonnnn commented Apr 5, 2023

Would love to be able to do colorize('#87CEEBFlight &8Master')

@Pieter12345
Copy link
Contributor

Appears that colorize(&#11223344) does work, but is not documented. That reforms the feature request to updating the colorize() documentation.

afbeelding

@malonnnn
Copy link
Author

malonnnn commented Apr 6, 2023

The issue I'm having...

from a YML file, I have:

niceName: '&#FF00BBTest &1T&2e&3s&4t &#888888Test'

Then I read it in:

@char = read('./rpgClasses/'.@class)
@char = yml_decode(@char)

Then I print it:

ptellraw(@player, array(array(text: colorize(@char['niceName']))))

But it looks like:

https://i.imgur.com/1AI5GY2.png

The first word is a completely wrong color (looks like AQUA), and the 3rd word looks more like DARK_GRAY on my screenshot, and more like GRAY on yours. The hex colors are becoming the "standard" minecraft/terminal colors for me

@PseudoKnight
Copy link
Contributor

Oh, that's because you're using ptellraw(), which doesn't really support hex colors in the text value. (it seems to be using the last color code from the hex code, in this case: 'B') Use text component colors there instead.

@PseudoKnight
Copy link
Contributor

e.g. ptellraw(@player, array(array(color: '#FF00BB', text: 'Test')))

@malonnnn
Copy link
Author

malonnnn commented Apr 6, 2023

What about trying to do multiple fancy color codes?

&#FF0000T&#BB0000e&#880000s&#330000t

I would still like to be able to easily do that

edit: oh wait, are you saying i should reopen this as a feature request to ptellraw?

@PseudoKnight
Copy link
Contributor

Multiple colors would require multiple text components.

ptellraw(@player, array(array(color: '#FF0000', text: 'T'), array(color: '#BB0000, text: 'e'), array(color: '#880000', text: 's'), array(color: '#330000', text: 't')))

This is just the json text format mojang uses. https://minecraft.fandom.com/wiki/Raw_JSON_text_format

@malonnnn
Copy link
Author

malonnnn commented Apr 6, 2023

So are you saying I can't have a feature request to simplify this process?

Like how would I store a complicated colored name in a yaml file? I mean since ptellraw supports standard color codes already, I feel it should also support hex.

@PseudoKnight
Copy link
Contributor

It's complicated. You're using ptellraw(), which expects a specific vanilla format. The hex code format was never vanilla to begin with. So while the client can still handle the old color codes, the hex format is not supported. It only works with msg() because Spigot converts hex color codes to the json format before sending it to the client. I wrote some rough code on my server to approximately convert to mojang json text format, but an alternative some people are using is minimessage() in CHPaper. It's more 1:1 with the json format. https://docs.advntr.dev/minimessage/format.html

@malonnnn
Copy link
Author

malonnnn commented Apr 6, 2023

Oh wow okay, I'm using CHPaper already and I see that minimessage() is supported there... would that more or less be able to fully replace ptellraw() for me?

@PseudoKnight
Copy link
Contributor

Yes. It supports all the most common features that you'd likely use. There's pros and cons to each approach, but I think minimessage would fit your use case quite well, if you like the format.

@malonnnn malonnnn closed this as completed Apr 6, 2023
@LadyCailin
Copy link
Member

We should still update the docs for colorize to indicate that they support hex colors.

@LadyCailin LadyCailin reopened this Apr 6, 2023
@LadyCailin LadyCailin added the good first issue Wanna take a stab at contributing? Try this one! Should be easier than most. label Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation good first issue Wanna take a stab at contributing? Try this one! Should be easier than most.
Projects
None yet
Development

No branches or pull requests

4 participants