NEW ChatColors.

Discussion in 'Plugin Development' started by nicholasntp, May 31, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    Now if your answer is no this is not possible, tell me the reason why (prove it). I dont like hearing people say its not possible, but in the end, it is.

    Now for the question.

    Is it possible to have custom chat colors? For example using Red, Blue, Green values, or even Hex Colors? If this is possible, I think colors would be too. Maybe something of the sort...

    NewChatColor color = new NewChatColor(r,b,g)
    player.sendMessage(color.toString() + "New colored string")
  2. Offline


    The colors are part of the client. You can't add them from the server.
  3. That is possible because the characters are already in the client, not like the colors.
  4. Offline


    If you want to add colors that arent in the vanilla client you might have to use Spout and Spoutcraft.
  5. Offline

    Father Of Time

    I believe chat colors are handled via an enum of ANSI color codes, meaning using reflections to manipulate the enumerator server side will likely allow you to introduce any number of colors you like.

    I researched this awhile ago, confirmed that the enum is stored server side (both server and client, but the server is used for SMP), but I never personally attempted to add new color due to time; however I brought up the concept with our development team and several members stated that they had personally done this, and that it does in fact work.

    So I can't personally confirm whether this is doable, but due to personal knowledge and trusted comments by other developers I would lean towards "this can be done".
  6. Offline


    I doubt it's possible without a client mod. All the server does is send a letter code, and there's no way for the server to tell the client what that new letter code actually means.
  7. its not posiable because the way the chat works
  8. Offline

    Father Of Time

    But I believe it's the file that filters out the unwanted ANSI code just like in my special character post, which is handled server side; I don't believe it would be blocked, but even if it was I would imagine you could use reflections to correct that as well in a similar fashion that I used to add special characters.

    I truly don't know and I am only speculating, but with my current understanding of chat filters and suggestions by other developers I would put this into the category of "It may not be possible, but I'm not willing to close the book on it just yet".

    I've got to know, what exactly are you basing this statement on? Can you show us the craftbukkit/bukkit or client source code that definitively prove you are correct?

    I am sorry, but I really dislike people just claiming "it can't be done" because they don't know of a method to achieve their goal; such statements can be detrimental towards learning and the growth of the community.

    ferrybig, It's one thing to say "I don't think it can be done" or "It's unlikely", but to state that it can't as fact with no evidence is just a horrible practice...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 26, 2016
  9. prove us that your right
  10. Offline

    Father Of Time

    I just did a fast search, the enum is stored in Bukkit server side:

    So in theory you should be able to alter this enum using reflections; if that is true then the question would be "would the client attempt to filter out the unexpected ANSI code", which I would then respond "maybe, but that can be altered by using reflections on", which I have already proven was possible in another thread regarding special characters.

    My brief research prove nothing, but it does show that there is enough evidence to warrant experimentation and not just a blanket "it cant be done" statement...

    Simply wow… First off I don’t need to prove anything to you… If you are happy living life in ignorance that is your prerogative, I can’t help that you aren’t a naturally inquisitive person…

    Secondly, even though I don’t have to prove anything I am going to anyways just in spite of your arrogance. That post that you provided also says that the usable characters in the Minecraft client are restricted to those characters listed, yet I definitively proved that it was possible to bypass that limitation and print any Unicode character in chat utilizing reflections:♠-♣-♥-♦-in-chat.72293/

    Notice how the first 5 to 10 post were all individuals saying “it can’t be done” over and over, yet I was persistent, did research, developed experiments and tested… I failed several times, but persistence paid off and thanks to that the community can now print any character they want…

    All I am getting at is to be insistent that something can’t be done, and then to be rude towards those who question your reasoning for believing false information is just a show of your poor character.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 26, 2016
  11. Offline


    The thing you don't seem to understand is that when the server wants to communicate a color to the client, it sends a special character followed by a number or letter code. That's it. The server doesn't do anything else with the color. It's up to the client to interpret that letter/number and turn it into a color. The fact is, the client only knows how to do this with the colors that are already specified. Adding another option to Bukkit's enum won't tell the client what color that is. If the client sees that it should use the color 't', how does it know what in the world that means? It doesn't. It knows the colors 0-9 and a-f, and the fake "colors" k-o and r.
    Bone008 likes this.
  12. Offline


    Thanks Father Of Time , I think you are right. Ill look in to minecraft's code and try to prove it can be done! Because i believe it can too! :D
    CorrieKay likes this.
  13. Offline


    If you find out this is possible, please let me know, this would be awesome! Slap on a config and this would be a great chat plugin!
  14. Offline


    That's only the shortcut to get to it...I believe so, anyways.

    I doubt that the only way to access colors in chat ever.

    From those shortcut colors, there are more (like Father of Time said), just not identifiable. If he was to communicate with the new values, and assign new 'shortcuts' to them, it'd work the same as the other colors.
  15. Offline


    If I figure this out, Ill make n API faster than you could say " nicholasntp , PLEASE PLEASE PLEASE made an API!"

    There are methods in about the colors 0-9, a-f, k,o,m,l,r and \247, the §, or Section Sign.

    I dont really understand it, and would have to look more in depth. Are there any unicode or ANSI code for colors? XD *facepalm*

    Check out line 435 in Minecraft, 1.2.5

    That is interesting.

    OpenGL Renders the colors in the string to be shown in the game as colored strings. Very interesting stuff.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 26, 2016
    caldabeast likes this.
  16. Offline


  17. Offline


    The client has this function that makes you colour it in a hex code.

    Like fontrenderer.drawString("derp", 0, 0, 0xhexcode);

    Like 0x888800 gives out a darker yellow
  18. You're mixing up ANSI and ASCII...
  19. Unfortunately, I have to join the side of people saying "it's not possible without a client mod" (as of 1.2.5).

    Basically, the problem is that the server does not send colors, but "aliases" for colors. The way a client is told to display for example a yellow string would be:
    §eThis text is yellow.
    "§" is the magical character here. When the client reads it, it takes the next character ("e" in this case) and turns the following text into the color for that char.

    However, the client needs to have that knowledge that "e" stands for a yellow color.
    As previously mentioned, that knowledge only exists in the client for the characters 0-9, a-f (and k, o, m, l and r since formatting was introduced).

    ChatColor is only a bukkit class (enum) that provides an alias for those characters. You don't even need it to send colors. Using reflection to enhance it doesn't get you any further. Look at those two lines, they do exactly the same:
    player.sendMessage(ChatColor.YELLOW + "This text is yellow.");
    player.sendMessage("§eThis text is yellow.");
    That's because ChatColor overrides toString() to print out that "§" sequence.

    If you now tried to send for example "§g" (which is easily possible by just writing it down), nothing special would happen because the client doesn't know what color "g" is supposed to be.

    You solved the problem with special characters. That was possible because the client actually knows how to render all those characters. I don't know if it knew it before the multi-language update, but since then there were implementations for all those special characters (e.g. "ß" is needed in German, after all).
    The problem was "just" that the server filtered its output, not that the client didn't know the characters.
    In the case of colors, the latter is true, though.

    To provide another analogy: Try making the client render another block. Adding a constant to the Material class with reflection won't really help you. When you tell the (unmodded) client "the block at x, y, z has the id 241" (that id doesn't exist), it won't magically start drawing unkown textures because in your head (or on the server, makes no difference to the client) you know that 241 is "Herpy Derpy Block".

    Unfortunate conclusion: You can't make the client render a new color, because you can't tell it new §-codes.

    You know I am a big fan of investigating and trying to break out of boundaries, but if Mojang puts limitations in the client, we have to live with that.
  20. Offline


    Dinnerbone How about slightly tweaking the ways chat colors work?
  21. Offline


    ChatColor is an alias for the alias, §a-f,0-9 and so on. Redstone_Craft has a good point. If we can get the client's font renderer to render the chat msg with an alternate hex code, then problem solved.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 26, 2016
  22. Could you please post the method you are talking about? I don't have a decompiled 1.2.5 vanilla client and MCP doesn't always output 100% the same code, so line numbers might not be the same.

    Yes, that's what I was saying (that ChatColor is redundant in this situation).

    But one does not simply make the client render text in a new color - through a network packet. There are tons of useful methods in the client, but you can't access them.
    Of course you can go ahead and try finding a way, but there is no foundation you could use (the §-notation doesn't work, that's what I explained up there).
    The only thing I could imagine would be a completely unused color structure that happens to be sent through the network and that isn't documented anywhere. Granted, it's not very likely to be there, but good luck ;-)
  23. Offline


    I dont know if it is copyright infringement, am I allowed to post a line?
  24. Offline


    I would personally see nothing wrong of posting one line of code in the name of science, but then again, what do I know?
  25. Offline


    Who cares? People could find it anyway with MCP, and I'm pretty sure all Minecraft mods would be copyright infringement since they're re-releasing his code.
  26. Offline


    int l = colorCode[j];
    GL11.glColor3f((float)(l >> 16) / 255F, (float)(l >> 8 & 0xff) / 255F, (float)(l & 0xff) / 255F);

    Search for that code and look at the whole method it is in. :)
  27. Offline


    That line of code is turning the renderer color into the specified color. I'm not sure it will be possible at this point because the packets send aliases for the colors. To make it have "custom" colors, the packets would have to be modified to be something like "short red, short green, short blue, String message".

    Edit: Maybe we could nicely ask a Bukkit member to change that in both the client and the server?
  28. Offline


    Yeah, good idea!

    Well now I am sorry to the people who said it cant be done, because it really cant from the server, YET.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page